Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

focus on the new window.open window

2 views
Skip to first unread message

Csaba Gabor

unread,
Nov 30, 2005, 10:04:03 AM11/30/05
to
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

Message has been deleted

Thomas 'PointedEars' Lahn

unread,
Nov 30, 2005, 10:40:15 AM11/30/05
to
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

Gérard Talbot

unread,
Dec 1, 2005, 12:38:09 AM12/1/05
to
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
--
remove blah to email me

Csaba Gabor

unread,
Dec 1, 2005, 5:20:48 AM12/1/05
to
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/DOM:window.open#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

Gérard Talbot

unread,
Dec 1, 2005, 11:06:13 AM12/1/05
to
Csaba Gabor a écrit :


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/Netscape7Section/Popup/PopupAndNetscape7.html#RaiseLowerSetting


> 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

0 new messages