Ask a questionAsk a question
 

QuestionIE8 window.focus() Issue

  • Friday, July 17, 2009 12:20 AMMiek Abel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a project with a main window that keeps references to windows that open on the site.  All window.open() 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. 

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

    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. 

    Thanks

All Replies

  • Sunday, July 19, 2009 10:28 PMIECUSTOMIZERMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Check your IE8 tabbed browsing settings....

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

    and

    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.

    Regards.
    Rob^_^
  • Thursday, July 23, 2009 10:39 PMMiek Abel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 byMiek Abel Thursday, July 23, 2009 10:41 PM
    •  
  • Monday, August 03, 2009 5:03 PMfattymelt Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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 =  window.open(...);
    mainAppWindow.focus();
        
    
    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!
  • Tuesday, August 11, 2009 1:45 AMhatzhang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It seems that ie8's focus no longer brings child windows (such as those created with the open method) to the foreground. 

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

    Is there any other way to do this? It's an important feature. 
    • Edited byhatzhang Tuesday, August 11, 2009 1:50 AM
    •  
  • Tuesday, August 11, 2009 7:56 PMPhoenixAlly Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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)
        {
            poppedWindow=window.open(myurl,'mywin','width=200,height=200,scrollbars=1,resizable=1');

            if(poppedWindow)
            {
                poppedWindow.focus();   
            }
            else
            {
                location.href=myurl;
            }
        }
        else
        {
            //if the window exists, replace it's current url with passed url, then focus window

            poppedWindow.location.href=myurl;
            poppedWindow.focus();   
        }
    }
  • Monday, August 17, 2009 7:54 AMウィンドウズスクリプトプログラマ Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sub MsgActivate(win)
    win.focus
    win.document.focus
    If win.document.hasFocus() Then Exit Sub
    win.setTimeout "MsgBox ""focus moving..."",vbSystemModal",0,"vbscript"
    End Sub