IE8 window.focus() Issue


  • I have a project with a main window that keeps references to windows that open on the site.  All calls go through this main window.  

    On IE7 and FF I've been able to use the window.focus() function to give focus to whichever window I wanted, using the stored references.  In IE8 it doesn't appear to work at all.  

    I made this very simple example: 2 links, one opens a new window called FocusExample_Window2.html and gives it focus - you then manually focus back on the main page and click the second link which gives focus to the window you just opened.  You see the window flash yellow in the taskbar but it doesn't give focus. 

    	<a href="" onclick="OpenNewWindow(); return false;">Open the Window</a>
    	<a href="" onclick="FocusNewWindow(); return false;">Focus on Window</a>
    	<script language="javascript" type="text/javascript">
    		var newWin = null;
    		function OpenNewWindow() 
    			newWin ='FocusExample_Window2.html','popup','width=550, height=262, toolbar=0, resizable=false');
    		function FocusNewWindow()
    			if (newWin != null && !newWin.closed)

    I have also tried calling functions on the new window, that just call 'window.focus()' - but that gives the same result. 

    Any help or solution to get around this would be greatly appreciated. 


    Friday, July 17, 2009 12:20 AM

All replies

  • Hi,

    Check your IE8 tabbed browsing settings....

    When a popup is encoutered..... open in a new window


    ensure that your web site domain is included in the IE8 popup white list or that your site is in the Trusted Sites zone where the popup blocker is disabled by default.

    Sunday, July 19, 2009 10:28 PM
  • I have popup blocking disabled and have set it to Trusted Sites zone, and popups open in a new window, still having the same issue.   

    This happens in IE8 normal mode and compatibility mode.  On IE7 and other browsers this works fine.  

    I can simply open a popup window and then on the new window, have a button with onclick="window.opener.focus(); return false;" and it will simply stay on the popup window.  It's as if IE8 completely ignores window focusing. 

    • Edited by Miek Abel Thursday, July 23, 2009 10:41 PM
    Thursday, July 23, 2009 10:39 PM
  • I don't have an answer, but I may have something to add. I do something roughly similar to what you are doing. I open a new window, assign it to a reference, and then using that reference attempt to call .focus. Like this:

    mainAppWindow =;
    When I do this, the newly opened page has strange errors like "Image is undefined" but if I take out the call to focus there are no errors on the newly opened page!
    Monday, August 3, 2009 5:03 PM
  • It seems that ie8's focus no longer brings child windows (such as those created with the open method) to the foreground.,VS.85).aspx

    Is there any other way to do this? It's an important feature. 
    • Edited by hatzhang Tuesday, August 11, 2009 1:50 AM
    Tuesday, August 11, 2009 1:45 AM
  • I use this function to popup a new window.  It works for all browsers (so far).  Is all of it logical?  No.  But after hours of aggravation it seems to work.

    function popupWindow(myurl)
        var poppedWindow;

        the stuff below doesn't make sense.  How can popped window be true
        and false at the same time?  Who knows but in ie, if you don't
        do it this way, you get an error

        if(!poppedWindow || poppedWindow.closed)

            //if the window exists, replace it's current url with passed url, then focus window

    Tuesday, August 11, 2009 7:56 PM
  • For anyone struggling with this issue who comes across this thread, Microsoft have sorted out the problem with an update for IE8.

    It describes how when you use window.focus(), all you will get is that window flash in the taskbar, but it will NOT be brought into the foreground unless you apply the update suggested:



    • Proposed as answer by wibwab Wednesday, February 1, 2012 3:37 PM
    Wednesday, February 1, 2012 3:36 PM
  • After what seemed like an eternity, my colleague figured out a way to make it work for us.

    We simply put the window.focus() in the body tag of the new (pop-up) page.

    <body onload="FocusWindow()">

    Defined FocusWindow() in a separate .js file as follows,

    function FocusWindow() {
    Tuesday, April 23, 2013 1:59 PM