424,303 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,303 IT Pros & Developers. It's quick & easy.

focus on the new window.open window

P: n/a
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

Nov 30 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Csaba Gabor wrote:
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
Nov 30 '05 #2

P: n/a
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...Best_practices

Gérard
--
remove blah to email me
Dec 1 '05 #3

P: n/a
Gérard Talbot wrote:
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.


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();
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...Best_practices


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

Dec 1 '05 #4

P: n/a
Csaba Gabor a écrit :
Gérard Talbot wrote:
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.

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();

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...Best_practices

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.

Speak up where it counts:
https://bugzilla.mozilla.org/show_bug.cgi?id=299424#c7
"(2) Raise or lower windows
Should be disallowed by default. (...)"
I have right here:
https://bugzilla.mozilla.org/show_bug.cgi?id=299424#c8
and also
http://www.gtalbot.org/Netscape7Sect...seLowerSetting

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.
Very bad approach that I have denounced already/before.

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.
The bandwidth "cost" is more important that the repositioning. If the
position (screenX, screenY, left or top coordinates) have not been
defined, then the new window is positioned at the coordinates of the
last opened non-maximized window: error compensation/correction
mechanism to sanitize position will apply.

// picking a unique name effectively guarantees this
// window, if it exists, was opened by script.
I wouldn't say that. Using an unique name is very helpful in trying to
recycle, to reuse an already opened window, though.

And if // it didn't exist before, it does now
var myWin = window.open("about:blank", "_Result");
You can't start a window name with "_". Invalid.
// So we close it
myWin.close();
Default value of
dom.allow_scripts_to_close_windows
is false in Firefox 1.5. So, you can not just close a window, just like
that.
// to ensure the following line brings it to the top
myWin = window.open("about:blank", "_Result");
// even when .focus() is disabled
myWin.focus();


Gérard
--
remove blah to email me
Dec 1 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.