views:

13

answers:

1

I don't know exactly the cause of this symptom but here goes. In our web app, we call window.open to open a new window/tab (internally everyone's is set to open in a new tab). After opening this new tab, IE8 immediately switches the focus to it.

We then integrated a web service, so we call this web service which in turn invokes a callback javascript function when it returns. We are now calling window.open from inside the callback function. When we do this, IE8 opens the new tab but does not switch the focus. Calls to window.focus on the parent page and the child page do nothing.

Now, I know javascript is not threaded, but is this something to do with asynchronicity? Is there a way to get the browser to behave as expected?

+2  A: 

I believe that by default, IE will only switch focus to the new tab if it was opened as a result of a user-initiated action such as a click. If the window.open call is not in response to a UI action then IE is probably opening the tab in the background as if it were some kind of popup, though obviously it's not being blocked by the popup blocker.

If you are in an intranet environment and can specify settings, have you tried setting the "Always switch to new tabs when they are created" check box on the tabbed browsing settings dialog?

Josh Einstein
*forehead slap* That makes perfect sense. We will do this. Just out of interest, do you reckon populating the browser's `event` object would alter the behavior? Maybe it could trick the browser.
Duracell
I doubt that workaround would have any effect. IE is almost certainly checking for this scenario in the code of the browser chrome itself, not the DOM.
Josh Einstein