473,416 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

focus on the new window.open window

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
4 3574
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: N/A | last post by:
Hey all, If I open a popup like this window.open('http://www.google.com', 'popup', 'width = 618, height = 425, directories = no, location = no, menubar = no, resizable = no, scrollbars = yes,...
2
by: Fred Snider | last post by:
Help! Opening a new window using the window.open( ) command works great for opening new windows and having them on top and having the focus. The window.focus command brings any existing...
31
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page...
13
by: Richard Shewmaker | last post by:
I've only recently returned to (trying to) doing simple JS, so this is probably a really lame question. I have a Web page with a series of graphics in it (window A). Clicking on a graphic in A...
11
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz...
7
by: marty.overdear | last post by:
I am opening a new window using window.open. I need the new window to open on top of the parent everytime. I cannot use onBlur b/c the user will need to click back to the parent for information. ...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.