Giving a child window focus in IE8

13,191

Solution 1

I figured out what the issue was - turns out the reason running window.focus() in the onload wasn't working was because the first window.open().focus() call caused it to start flashing in the background, and after that any subsequent focus calls wouldn't work. If I don't try to focus it from the calling window but only from the popup it comes to the front normally. What an annoying "feature"...

Solution 2

The IE8 is not allowing this feature because of security issues

Windows Internet Explorer 8 and later. The focus method no longer brings child windows (such as those created with the open method) to the foreground. Child windows now request focus from the user, usually by flashing the title bar. To directly bring the window to the foreground, add script to the child window that calls the focus method of its window object

http://msdn.microsoft.com/en-us/library/ms536425%28VS.85%29.aspx

Share:
13,191
Andrew K
Author by

Andrew K

Updated on June 27, 2022

Comments

  • Andrew K
    Andrew K almost 2 years

    I'm trying to launch a popup window from a Javascript function and ensure it has focus using the following call:

    window.open(popupUrl, popupName, "...").focus();

    It works in every other browser, but IE8 leaves the new window in the background with the flashing orange taskbar notification. Apparently this is a feature of IE8:

    http://msdn.microsoft.com/en-us/library/ms536425(VS.85).aspx

    It says that I should be able to focus the window by making a focus() call originating from the new page, but that doesn't seem to work either. I've tried inserting window.focus() in script tags in the page and the body's onload but it has no effect. Is there something I'm missing about making a focus() call as the page loads, or another way to launch a popup that IE8 won't hide?