Window.Focus on Safari

J

Jayesh Modha

Hi All,

This is probably old topic found on internet but none of them seems to
have solution or at least I haven't got the solution from internet
forums yet.

I would really appreciate if you have any information about this
issue. I am sure many of web developers must have faced this problem.

Window.Focus() method does not seem to work on Safari browser. Here's
is the small code snippet.

function LaunchNewWindow(Url, WindowName,allOptions)
{
var win = window.open(Url, WindowName,allOptions);
win.focus()
}

This code seems to work fine with IE, FF but not with safari/chrome/
opera

Any help on this topic is highly appreciated.

Thanks,
Jayesh Modha
 
S

SAM

Le 9/3/09 6:51 PM, Jayesh Modha a écrit :
Window.Focus() method does not seem to work on Safari browser. Here's
is the small code snippet.

thre is no reason to do not work
from the moment popups are allowed by the browser
function LaunchNewWindow(Url, WindowName,allOptions)
{
var win = window.open(Url, WindowName,allOptions);
win.focus()
}

This code seems to work fine with IE, FF but not with safari/chrome/
opera

What do you smoke ?
That runs fine with my Safari, my Opera, my Fx ...
 
J

Jayesh Modha

Some browsers allow the user to block certain JS operations. For
example, Firefox has an "advanced" JS setting: "raise or lower windows".
I don't have a lot of experience with Safari or Chrome, but Opera has
"allow raising of windows" and "allow lowering of windows", both of
which are set to false in my installation (I don't remember if that was
the default). In that case, there's nothing you can do with JavaScript
to focus the new window*.

Another possibility is that win.focus is called before the new window is
actually available or able to react to 'focus' (race condition: might
work fine for SAM but fail for Jayesh). If that's the case, you could
try to embed the "self.focus()" call in the newly opened page, or you
could try to set an (arbitrary) timeout before you call win.focus.

cheers,
stefan

*PS: I think I remember having scripts throw an exception here if "raise
window" was blocked by the user. Not sure about this, and I can't seem
to reproduce it now, but some of my code still has the focus() calls
wrapped in try/catch blocks, so I guess it must have been a problem at
some time.

Thanks a lot to both of you to reply. I am having this issue Safari
3.0 and it works with Safari 4.0. Sam which version of safari you are
running?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top