focus on the new window.open window

C

Csaba Gabor

Up until a few weeks ago, javascript code like

window.open("http://mydomain.com", "windowName");

would always bring my new or reused window to the top, with focus.
Lately, Firefox (Deer park alpha 2) only brings it to the top if the
window is new. If it's being reused, the window does not come to
the foreground (with IE 6 it does).

Is there a new way in Mozilla/Firefox that I can ensure that this
window
comes to the top?

Thanks,
Csaba Gabor from Vienna
 
L

Lee

Csaba Gabor said:
Up until a few weeks ago, javascript code like

window.open("http://mydomain.com", "windowName");

would always bring my new or reused window to the top, with focus.
Lately, Firefox (Deer park alpha 2) only brings it to the top if the
window is new. If it's being reused, the window does not come to
the foreground (with IE 6 it does).

Is there a new way in Mozilla/Firefox that I can ensure that this
window
comes to the top?

window.open("http://mydomain.com", "windowName").focus();
 
T

Thomas 'PointedEars' Lahn

Csaba said:
Up until a few weeks ago, javascript code like

window.open("http://mydomain.com", "windowName");

would always bring my new or reused window to the top, with focus.
Lately, Firefox (Deer park alpha 2) only brings it to the top if the
window is new. If it's being reused, the window does not come to
the foreground (with IE 6 it does).

I do not think there is a significant change here. It is well-known
that reused windows are not always and everywhere focused.

However, Firefox 1.5 is out now, so I do not think Deer Park _alphas_
do really matter anymore. (I have not installed Firefox 1.5 yet.)
Is there a new way in Mozilla/Firefox that I can ensure that this
window comes to the top?

You could call the focus() method of the respective Window object
after it has been established on runtime that there are both:

function isMethodType(s)
{
return (s == "function" || s == "object");
}

var w = window.open(...);
if (w && !w.closed && isMethodType(typeof w.focus))
{
w.focus();
}


PointedEars
 
G

Gérard Talbot

Csaba Gabor a écrit :
Up until a few weeks ago, javascript code like

window.open("http://mydomain.com", "windowName");

would always bring my new or reused window to the top, with focus.

No. Only new windows.
Lately, Firefox (Deer park alpha 2) only brings it to the top if the
window is new. If it's being reused, the window does not come to
the foreground (with IE 6 it does).

No. Check again carefully. IE 6 does not bring back on top an already
used window.
Is there a new way in Mozilla/Firefox that I can ensure that this
window
comes to the top?

This is already well explained at:

http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices

Gérard
 
C

Csaba Gabor

Gérard Talbot said:
Csaba Gabor a écrit :

No. Only new windows.


No. Check again carefully. IE 6 does not bring back on top an already
used window.

Lee, PointedEars, and Gérard, thank you for your reply.
My apologies because Gérard is correct in what he writes above.
Indeed, I had left out that I was doing a subsequent .focus(),
which had been working well on both IE and FF till about two
weeks ago on FF:

var myWin = window.open("about:blank", "_Result");
myWin.focus();

I'm familiar with those pages on the window object, and they are quite
well done. I especially appreciate the diagram covering the naming of
various items on the page, and the explanations for all the
properties/methods/events.

However, the behaviour I am experiencing is not covered there. The
version of Firefox that I have (1.6a1 = Deer Park alpha 2) has new
"features" restricting this behaviour by default, it seems.
Specifically, if, in Firefox, I go to Tool / Options / Conent tab /
Enable Javascript is checked / Advanced button (to the right of Enable
Javascript), then I get a dialog box listing 5 checkbox buttons:
Move or resize existing windows
Raise or lower windows
Disable or replace context menus
Hide the status bar
Change the status bar text

Unfortunately, automatic update unchecked both of the top two options
for me. .focus() has no effect if Raise or lower windows is not
checked. Frankly, it seems wrong for automatic update to have changed
my settings without any warning, but even moreso, I would not expect
this behaviour to apply to a parent-child window. I would expect that
related windows can alter their relative Z-indexes. Otherwise you get
the really bad situation where one page changes another (consider a web
app writing to an output window) and the user has to cycle through a
boatload of windows to find it, assuming that he's aware that it might
have changed at all. Not a good situation in the least.

In addition, there is the grossly brute force approach of writing the
window once to get ownership and a reference to it, closing the window,
then opening it for real. This is also not very nice because prior
repositioning/resizing information that the user may have set is lost
in addition to extra bandwidth, thrashing.

// picking a unique name effectively guarantees this
// window, if it exists, was opened by script. And if
// it didn't exist before, it does now
var myWin = window.open("about:blank", "_Result");
// So we close it
myWin.close();
// to ensure the following line brings it to the top
myWin = window.open("about:blank", "_Result");
// even when .focus() is disabled
myWin.focus();

Csaba Gabor from Vienna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,104
Latest member
LesliVqm09
Top