In Javascript, how to reuse a window previously opened by another page - javascript

I have a window which uses javascript to open another child window, in the standard window.open("http://foobar","name") manner. If I open again with the same name, it reuses the window. This is great and exactly what I want.
However, if the original window is closed, I would like to be able to reopen it and have its window.open go to the previously opened child window. Unfortunately, because it is a new parent window it will open another child window (which it will happily and correctly reuse).
Does anybody here know of a way to get hold of that previous child window so I can avoid making more windows than necessary?
Behind the scenes, the driver of this question is this: I have a java program which will periodically open different websites and I do not want to force a plethora of tabs or windows. Command-line options do not let you reuse windows or declare targets; javascript lets you declare a target. I figured I would write a small javascript page which opened a page in a specifically-named window and then close itself. Anytime you want to see a new page, hit that page passing in your new page.... Much to my dismay, though, targets seem specific to the window which creates them.
So if you have ideas which are relevant to my actual problem I'm interested too.

Embedding a browser took less time than trying various ways of controlling browsers.

Related

Implications of using multiple interactive popup windows

I'm coming up with the idea of detaching elements onto popup windows. Make a popup with window.open(), set up some elements in that document and add event listeners to serve the original purpose, but as a popup window component. All of this works, and it seems that the created window is handled by the same thread.
Is this "technique" bug-prone by any chance? I.g: If I create a canvas in the popup window and get a WebGL context from it, will it work flawlessly? If I set a bunch of event listeners there, will I get callbacks from them without any delay?
I couldn't do my research on this one because almost no one does this. Through my life, I've seen many sites use popup windows for user inputs but not for interactive or real timey stuff. I'm building a web app that's complex that utilising multiple monitors would benefit in user experience. You know, at least I know how painful it is to have two monitors and be unable to use both of them because all the component of the app is cramped in a single window. Just imagine using an MDI version of Photoshop where all the toolbox is within the MDI area and you can't get them out of the app window. A web page is exactly that.
Although this is non-conventional it definitely seems to suit the requirement you mentioned. I don't see any issues when it comes to the browser support for handling rendition or communication across the windows, it's just that you will need to be more careful with your code. Something like make frequent checks in case user has closed one of your pop-ups(or register a window close callback so that you can make necessary adjustments).
Eventing across the windows should also be fine. Refer http://help.dottoro.com/ljrwrqew.php which has exactly same example of attaching the event callback from one window to another.
Another good read is http://www.infimum.dk/HTML/JSwindows.html
One possible drawback could be that the popup can be blocked by the browser popup blocker (but yes, you could inform the user to don't block the popup coming from your web application)
Another one could be that the dimensions of the popup that you specify on your javascript code could be not respected (this is at the discretion of the browser), so for example one browser could open anytime the popup in a new tab or a new maximized window.
Here you will find some ready made experiments with multi-window: https://experiments.withgoogle.com/chrome?tag=Multi-Window
For data sharing between your main window and your popup you shouldn't have any problem.
Something to keep in mind is that not every browser use the same threading model, so you must do some performance tests as well on all the browser you will want to support and see the differences.

HTML in a window

I want to make a window with HTML that works similar to ones opened by windows. I know the method with actual browsers, but it isn't good enough as I have link and navigation buttons.
This would make my job easier in making softwares with lots of animations
The best you can get is calling Window.open with third argument set as: 'menubar=no,location=no,resizable=no,scrollbars=no,status=no'.
This will open a new browser window with only the address bar shown.
There is no way to open a native window out of the browser's scope from JavaScript code other than this. It is a security limitation.
However, the other alternatives include are Window.alert or a Window.prompt.
If you want to open a popup box you can use alert("This is a dialog box!");, confirm("Is it ok or not?"); or prompt("Enter a value and confirm it or not");.
https://www.w3schools.com/js/js_popup.asp
If you want to open a native window, that is not possible as it has already been said.

Can Javascript get information on any window?

A little bit ago I asked this question about if a child can get information on its parent. But now I realize that I have a followup question that belongs on its own, rather than in comments: Can Javascript find out if any window is open?
I have a window A which can either be called from window B or window C. However, when I close A, I want certain things in the onUnload only to happen if window C is closed. Now, A may not have been opened by C, so I can't rely on window.opener. Is there any way I can find out information on arbitrary windows? I thought about checking window.opener.location but that still requires that C have been the opener, which it may not have been. The names of all the windows are known, so if I could search by those, I'd be golden.
(as for the why: A is a chat console, B is the main menu, C is the queue monitor. When someone is in the queue monitor, they're marked as available for chat. But to actually chat, they have to load up the chat console to do so. Normally, when you close the chat console, an onUnload tries to mark you unavailable, but I don't want to that to happen if the queue monitor is still open.)
The only way to be able to do this is if the parent window that launched the child windows remains open throughout the process. Windows with similar "ancestry" can use the common parent as a relay point. Code on the common parent would probably be required (or at least desirable) to assist.
I suppose it's possible for the common parent to hand each child an object with references to other child windows; I can't imagine any reason for that to fail. Of course, that won't help if one child is launched from one incarnation of the main window, and another launched from a separate one. In that case, even though the windows share a domain, they really have no way of finding each other.
Anyway if you have a reference to a window, the .closed property will tell you if it's closed or not.

Maximizing the current window in javascript

Is there a way I can maximize a currently minimized window from Javascript? Here's my situation:
I have a series of links that all target the same external window (e.g. "MyNewWindow"). When I click a link, a new window pops up. If I click another link, the page pops up in the same window as expected. If I minimize the "MyNewWindow" popup, I'd like to be able to click another link and have that window maximize.
My approach was to put something on the onLoad part of the body so that when the page is refreshed it will automatically "maximize" if it is minimized. Note: Using window.MoveTo() and window.resizeTo() doesnt seem to do the trick (the window stays minimized).
Thanks!
For all of you know-it-alls, there are perfectly good reasons to want to know how to do this. Here's the reason I needed this:
I'm deploying SCORM modules to a variety of Learning Management Systems (LMSs)
One LMS that a client is using launches the module in a small (600x400) window, with the user controls to maximize or resize said window DISABLED
The client doesn't know how to change this launch behavior
My only option is to try to maximize via javascript, because the idiots who made the LMS took away the user's ability to manage their own windows.
window.moveTo(0, 0);
window.resizeTo(screen.availWidth, screen.availHeight);
This may not work in IE depending on the security zone your page is falling under, and it may not work in Chrome at all. But for a corporate environment in an intranet, it has a good chance of working.
Don't do this, you are not allowed to do this by most modern browsers for a reason.
In a tabbed environment you're not messing with only the window you may have created, but all of my tabs, that's unacceptable. It's the user's computer, user's browser, it's the user who chose to go to your site...let them size the window the way they want it, doing anything else breaks their experience...and their trust in your site.
The behavior you're looking to emulate is what your run-of-the-mill malware does...re-think your approach, please. For example focusing that window is appropriate for what you want, let the default behavior of the browser take over from there, like this:
var thatWindow = window.open(url, "linkWindow");
thatWindow.focus();
try to use window.open(url,fullscreen=yes);
if you out fullscreen=yes than while clinking on link automatically

Why does Firefox lose focus on page reload?

I have two instances of Firefox running simultaneously next to each other. One window is in the front and the other one in the background. Both instances use the same target URL.
Whenever I do a page reload in one of my instance the other instance loses the focus and gets minimized to the Windows taskbar.
Has anyone ever experienced this effect?
I've found the problem. Some buggy jQuery code returned a window reference rather than a DOM Element. The call to $(element).blur() ( element is a window reference ) now explains the strange behaviour.
Could be a buggy 'onunload' handler. If both windows are open to the same page, then doing a reload in one will trigger onunload, which eventually calls window.blur(). If both windows are child windows of the same parent page (ie: created via window.open(), or regular link with target="somename"), they could be assigned the same name.
I don't know what FF"s priorities are on conflicting window names in JavaScript, but you could try opening the two windows in various orders, and reloading one or the other and see which one minimizes (if at all).

Categories