views:

28

answers:

1

I have an issue with focusing a window. I am very new to JavaScript and any suggestion is appreciated. Kindly note that I am trying below issue in a shell which overrides many JavaScript functions. My Issue: on a single "click" action, I navigate to a new page which has 2 JavaScript methods which launch 2 external URLs which I don't own. For example I launch Yahoo.com and Google.com. My JS launches Yahoo.com in current window (as a page navigate) and Google.com as a pop-up. I WANT Google.com WINDOW TO BE FOCUSED irrespective of loading time of either URLs. The major issue is I cannot use the setTimeout JS function as this function's behavior is altered within the shell and is not usable.

Note: I am using a custom reusable JS function to launch external URLs and I just pass values to that method. So I don't even have access to window object. If I can somehow achieve a time delay without using setTimeout, it will be ideal case. If not, I will have to override that custom JS function, get access to the window object. Even if I have control over those window objects for external URLs, since loading times are different, setting focus to the Google window object is not always giving me the focus on Google window.

Sorry if my explanation is bad, I have tried to make it simple. Any suggestions?? (IE6 & 7)

(Apologies for witty title.)

A: 

You cannot guarantee the behavior you want, in general; browsers will not let you.

Safari generally ignores requests to focus windows. Firefox and I think Chrome can be configured by their users (not by your code) to allow focus requests, but by default they won't.

Pointy
Omi
Well, the main problem is that once you load google.com into that popup window, you'll (almost) completely lose control of it as its contents are from a domain different from yours. What *might* work would be to load the popup with your own page that calls `window.focus()` and then sets `location.href` to "http://www.google.com" (or whatever). Window focus is inherently fragile, however, especially in the click-to-focus Windows UI.
Pointy