简体   繁体   English

如何在IE9中启用javascript window.focus()

[英]How to enable javascript window.focus() in IE9

I've used: 我用过:

var win = window.open('http://www.google.co.uk','foo');

to open a new window I've then navigated back to the orginal window leaving the new window open and used: 打开一个新窗口,然后导航回原始窗口,使新窗口保持打开状态并使用:

win.focus();

I expected the browser to switch back to the foo window how ever IE9 ignores it and stays on the current window. 我希望浏览器能切换回foo窗口,无论IE9如何忽略它并停留在当前窗口中。 Works in chrome and IE6 I'm assuming this may have been disabled as a security risk. 在chrome和IE6中工作,我认为这可能已被禁用,因为存在安全风险。 Is there a way to enable window.focus in IE9 via security settings or registry settings? 有没有一种方法可以通过安全设置或注册表设置在IE9中启用window.focus?

This is my full code: 这是我的完整代码:

<a onclick="OpenWindow();">Click here to open a window</a><br />
<a onclick="SelectWindow();">click here to switch to window</a>

<script language="javascript" type="text/javascript">

var win;

function OpenWindow() {
    win = window.open("http://www.google.co.uk", "foo");
}

function SelectWindow() {
    win.focus();
}

</script>

It is a known bug in Internet Explorer 9 . 这是Internet Explorer 9中的一个已知错误 Check out the article, A web page may fail to get focus in Windows Internet Explorer 9 for more info. 请查看文章, 网页可能无法在Windows Internet Explorer 9中获得更多信息。

Registry Fix 注册表修复

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\
Type: REG_DWORD
Name: HangRecovery
Value: 0

A variation of the following has worked for me on all browsers since 2003: 自2003年以来,以下内容的变体对我所有的浏览器都有效:

function popupHelp(helpUrl) {
    helpWin = window.open(helpUrl, "help",
            "height=500,width=500,scrollbars,resizable,toolbar,status,menubar");
    if (helpWin != null) {
        setTimeout("helpWin.focus()",100);
    }
}

...

<a href="javascript:popupHelp('help.jsp')">Help</a>

As of 2013-08-27 it seems to be the feature list on the window.open() call that forces/allows IE 8, 9, and 10 to give the window focus a second time. 从2013-08-27开始,似乎是window.open()调用中的功能列表,强制/允许IE 8、9和10再次赋予窗口焦点。 I say window because it also forces IE to open in a window, not a tab (Chrome uses a tab, Firefox works like IE). 我说窗口是因为它也迫使IE在窗口而不是选项卡中打开(Chrome使用选项卡,Firefox的工作方式类似于IE)。 I wish all browsers worked like Chrome in this regard. 我希望所有浏览器在这方面都能像Chrome一样运行。 They all seem to open a new window with target="_blank" just fine, cluttering the users desktop with open windows, but reusing an existing window is something they don't want to do. 他们似乎都打开了一个带有target =“ _ blank”的新窗口,并用打开的窗口使用户桌面混乱,但是重用现有窗口是他们不想做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM