Connecting Tech Pros Worldwide Forums | Help | Site Map

focus on the new window.open window

Csaba Gabor
Guest
 
Posts: n/a
#1: Nov 30 '05
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


Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Nov 30 '05

re: focus on the new window.open window


Csaba Gabor wrote:
[color=blue]
> 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).[/color]

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.)
[color=blue]
> Is there a new way in Mozilla/Firefox that I can ensure that this
> window comes to the top?[/color]

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
Guest
 
Posts: n/a
#3: Dec 1 '05

re: focus on the new window.open window


Csaba Gabor a écrit :[color=blue]
> 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.[/color]

No. Only new windows.
[color=blue]
> 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).[/color]

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

This is already well explained at:

http://developer.mozilla.org/en/docs...Best_practices

Gérard
--
remove blah to email me
Csaba Gabor
Guest
 
Posts: n/a
#4: Dec 1 '05

re: focus on the new window.open window


Gérard Talbot wrote:[color=blue]
> Csaba Gabor a écrit :[color=green]
> > 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.[/color]
>
> No. Only new windows.
>[color=green]
> > 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).[/color]
>
> No. Check again carefully. IE 6 does not bring back on top an already
> used window.[/color]

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();
[color=blue][color=green]
> > Is there a new way in Mozilla/Firefox that I can ensure that
> > this window comes to the top?[/color]
>
> This is already well explained at:
>
> http://developer.mozilla.org/en/docs...Best_practices[/color]

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
Guest
 
Posts: n/a
#5: Dec 1 '05

re: focus on the new window.open window


Csaba Gabor a écrit :[color=blue]
> Gérard Talbot wrote:
>[color=green]
>>Csaba Gabor a écrit :
>>[color=darkred]
>>>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.[/color]
>>
>>No. Only new windows.
>>
>>[color=darkred]
>>>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).[/color]
>>
>>No. Check again carefully. IE 6 does not bring back on top an already
>>used window.[/color]
>
>
> 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();
>
>[color=green][color=darkred]
>>>Is there a new way in Mozilla/Firefox that I can ensure that
>>>this window comes to the top?[/color]
>>
>>This is already well explained at:
>>
>>http://developer.mozilla.org/en/docs...Best_practices[/color]
>
>
> 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.[/color]


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

[color=blue]
> 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.[/color]

Very bad approach that I have denounced already/before.

This is also not very nice because prior[color=blue]
> repositioning/resizing information that the user may have set is lost
> in addition to extra bandwidth, thrashing.[/color]

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.
[color=blue]
>
> // picking a unique name effectively guarantees this
> // window, if it exists, was opened by script.[/color]

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[color=blue]
> // it didn't exist before, it does now
> var myWin = window.open("about:blank", "_Result");[/color]

You can't start a window name with "_". Invalid.
[color=blue]
> // So we close it
> myWin.close();[/color]

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.
[color=blue]
> // to ensure the following line brings it to the top
> myWin = window.open("about:blank", "_Result");
> // even when .focus() is disabled
> myWin.focus();[/color]

Gérard
--
remove blah to email me
Closed Thread


Similar JavaScript / Ajax / DHTML bytes