tags:

views:

83

answers:

2

If you open a window like:

window.open ("url","winName","location=0,width=300,height=214");

If winName is already open it just changes the URL in the window. This is ok but if that window is behind the current window most users won't realize this and think that it is just not opening.

Is there anyway that if the window is already open, it brings it to the front?

A: 

window.focus() applied to the window in question should do the trick.

Robusto
Can you give me an example I tried: `editDaySched = window.open(...); editDaySched.focus();` in Chrome but it didn't seem to work. Thanks.
John Isaacks
If you are calling focus() inline like that it won't work because the window doesn't exist yet. What you should do is have a function in the opened window (here editDaySched) that calls window.focus() when the onload event fires. You can do a proof of concept from the opener with a setTimeout focusing the editDaySched window after, say, 5 or 6 seconds.
Robusto
+1  A: 

The window.open() method returns an object that represents the new window. You just need to window.focus() it:

var w = window.open ("url","winName","location=0,width=300,height=214");
w.focus();

Or simply:

window.open("url","winName","location=0,width=300,height=214").focus();
Álvaro G. Vicario