Giving child window focus in IE8

I am trying to launch a popup from a Javascript function and make sure it has focus using the following call:

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

It works in any other browser, but IE8 leaves a new window in the background with an 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 have to focus the window by making the focus () call coming from a new page, but that doesn't work either. I tried embedding window.focus () in the script tags on the page and loading the body, but that does not affect. Is there something that I am missing in the focus () call when loading the page or another way to launch a popup that IE8 does not hide?

+3
source share
5 answers

I realized what the problem was: it turns out that the reason window.focus () works in onload did not work, because the first call to window.open (). focus () made it start blinking in the background, and after that any subsequent focus calls would not work. If I do not try to focus it from the calling window, but only from the pop-up window, it usually comes to the fore. What an annoying "feature" ...

0
source

IE8 does not allow this feature due to security issues

Windows Internet Explorer 8 . (, ) . , , . , script ,

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

+1

. , , >

var isIE = (navigator.appName == "Microsoft Internet Explorer");
var hasFocus = true;
var active_element;

function setFocusEvents()   {
    active_element = document.activeElement;
    if (isIE)   {
        document.onfocusout = function() {  onWindowBlur();       }
        document.onfocusin = function()  {  onWindowFocus();     }
    }   else    {
        window.onblur = function()    { onWindowBlur();          }
        window.onfocus = function()  {  onWindowFocus();       }
    }
}

function onWindowFocus()    {
    hasFocus = true;
}

function onWindowBlur() {
    if (active_element != document.activeElement) {
        active_element = document.activeElement;
        return;
    }
    hasFocus = false;
}
0

, IE8 , document.ready body.onload:

test1.html:

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript"> 
            function openNewWindow()
            {
                window.open("test2.html", null, "height=200, width=200");
            }
        </script>
    </head>
    <body>                        
        <a onclick="openNewWindow()">Open</a>
   </body>
</html>

test2.html:

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript"> 
            $(document).ready(function(){ window.focus(); });
        </script>
    </head>
    <body>
        <div id="container" style="background:blue;height:200px;width:300px">
        </div>
   </body>
</html>
0

, Window.focus Internet Explorer 8 (IE 8). - IE 8 ; - , , , .

googling :

Microsoft , , , , , !

.

:

  • , .
  • ,
  • .

javascript :

function nameoflink()
{
    var nameofwindow = window.open('pagetolinkto.htm','nameofwindow','menubar=1,resizable=1,width=350,height=250');
    if (nameofwindow) {
        nameofwindow.close();
    }
    window.open('pagetolinkto.htm','nameofwindow,'menubar=1,resizable=1,width=350,height=250');
    return false;
}

:

<a href="#" onclick="nameoflink()">Click Here to go to name of link</a>

MS Windows 7 IE8, .

0
source

Source: https://habr.com/ru/post/1723162/


All Articles