Forum Moderators: open

Message Too Old, No Replies

Returning focus to pop-up window after its opening page is unloaded

         

robtherat007

4:01 pm on Mar 25, 2003 (gmt 0)

10+ Year Member



Hello

A link in the main browserwindow opens a popupwindow. After that the user may keep on browsing. When the user returns to a specifc page it is necessary to focus the popup again ( if it is still open) is there a way to do that? How van I acess a certain window at any time?

DrDoc

4:36 pm on Mar 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

You can always do this:

if(window_name.focus()) {
// do stuff
window_name.location.href = "whatever.html";
}
else {
window.open(...);
}

That will, if the window exists, move focus to that window before doing something (here, opening a new page in that window).

If the window doesn't exist, it will be created...

robtherat007

5:24 pm on Mar 25, 2003 (gmt 0)

10+ Year Member



With window_name you mean the popupwindow, right? If so, the new link (whatever.html) will be opened in the popupwindow anf not in the mainwindow.

Also:

Wheen I load a new Page into the main window there is no way to access the popup via window_name. A new Page was opened window_name is not known anymore in the main window. window_name.focus() on the new page is not possible anymore but the popupwindow still exists and it would be no need to open one ....

DrDoc

6:34 pm on Mar 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, window_name is the name of the pop-up window.

Well, I assume that it should still work, even if a new page is loaded (but, I could be wrong). I know you can't have two windows with the same name. So, window_name.focus() should work, shouldn't it?

robtherat007

7:00 pm on Mar 25, 2003 (gmt 0)

10+ Year Member



" ... Once the location of a page has changed, or the page has reloaded, it loses all knowledge about any windows it may have opened. ..."

when I put your code in the html-file that will be opened in the mainbrowserwindow a window with the reference object window_name is created and references to the popupwindow because of window_name=window.open(). This reference exitst only as long as the page (where it was defined) is loaded in the mainbrowserwindow. When this page is closed (i.e. by following a a link on this page) the reference is killed (but the window of course keeps on existing). On the new loaded bage we could again include the code above. Again a (new) reference is created and a popup will be opened. But it would not have been necessary to (re)open the window (and trigger traffic because of reloading the popuppage) because the window was still there ....

That`s what I assume ....

DrDoc

8:29 pm on Mar 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I know that it looses the whole variable=window.open() info...

But what if you do:
window.open("whatever.html","blah");

...where "blah" is the name of the window... Will it still not be able to find a window with that name? This is interesting :)