window.focus() with tabs in IE7

Consider the following HTML pages

Main.html

<html>
<head>
<title>MAIN</title>

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript1.2">
var desktopWindow = null;

function openDesktopWindow() {
if (desktopWindow == null || desktopWindow.closed) {
desktopWindow =
window.open('pop1.html',
"pop1",
'width=1024,height=768,menubar=0,status=1,toolbar=0,resizable=1');
}
}

function focusWindow() {
desktopWindow.focus();
}
</SCRIPT>

</head>
<body bgcolor="#E3E3E3">

<a href="#" onclick="openDesktopWindow(); return false">Open popup</a>
<br>
<a href="#" onclick="focusWindow(); return false">Focus popup</a>

</body>
</html>

pop1.html

<html>
<head>
<title>POP UP 1</title>
<body bgcolor="#E3E3E3">
<h1>POP UP 1</h1>
</body>
</html>

Be sure that IE7 open pop-up windows in a new window (like IE6). Open the file main.html. Clicking on the "Open popup" link will open the popup pop1.html. Clicking on the "Focus popup" link will bring back the popup to foreground.

Now configure IE7 to open pop-up windows in a new tab. Open the file main.html. Clicking on the "Open popup" link will open the popup pop1.html in a new tab. Clicking on the "Focus popup" link will not activate (set it to foreground) the popup tab.

My question is: Is it a bug Or if it is an expected behavior, why

Thanks you in advance.




Answer this question

window.focus() with tabs in IE7

  • Stinger_

    Hi There,

    I am calling window.focus() from a tabbed page which is not at the front, but this does not cause ie7 does not bring it to the front.

    Is there an alternative to do this

    Thanks,

    Ian


  • Davidjr1

    Hi Thibaut,

    You are seeing designed behavior. To limit opportunities for malicious behavior, scripts running in tabbed windows cannot affect other tabs. For more information, please see Tabbed Browsing for Developers.

    Hope this helps...

    -- Lance



  • chrisbacon

    Thank you very much. It is exactly what i was looking for!



  • alasaaa

    I'm having the same problem. Without tabs, window.focus() does the expected behavior, however, after opening other tabs and minimizing the browser, window.focus() does nothing. There has to be a way, other than using alerts, to get the browser window to focus even when there are multiple tabs. Firefox behaves as expected, why not IE
  • window.focus() with tabs in IE7