在window对象上调用focus()时遇到IE11的问题 [英] IE11-facing issue while calling focus() on window object

查看:456
本文介绍了在window对象上调用focus()时遇到IE11的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在IE11浏览器上运行以下简单代码:

Trying to run a following simple code on IE11 browser:

<!DOCTYPE html>
<html>

<head>
  <title>Popup Example</title>
  <script>
function ButtonClick2() {
var thewin = window.open("http://www.google.com",'thewin','width=400, height=420,status=no');            
window.thewin.focus();

        }

  </script>
</head>

<body>
   <button onclick="ButtonClick2()">Click Me!</button>
</body>

</html>

问题:在IE11上,它给出错误语句"无法获取未定义或空引用的属性"焦点"

ISSUE:On IE11 it gives the error statement "Unable to get property 'focus' of undefined or null reference"

推荐答案

这个答案很晚,但是我认为我会发布它,以防万一将来有人遇到这个问题.

This answer's late, but I thought that I'd post it just in case somebody came across this question in the future.

根据此处的答案: https://stackoverflow.com/a/7025648/1600090 , 根据我自己的经验,一个可能的原因可能是您试图在另一个启用了保护模式的Internet区域中打开一个窗口.默认情况下,IE11为Internet和受限区域启用保护模式,但对本地Intranet和受信任的站点禁用保护模式.因此,例如,如果您的页面(和/或站点)在本地Intranet区域中运行,并且您试图在Internet区域中打开一个新窗口,则window.open将返回空引用.如果启动新窗口的页面/站点位于Internet区域中,以我的经验,window.open将返回引用.因此,@ ssut在jsfiddle中的示例将起作用,因为jsfiddle.com和google.com可能都在同一区域中(我假设是Internet区域).

According to the answer here: https://stackoverflow.com/a/7025648/1600090, and my own experience, one possible cause could be that you're trying to open a window in a different internet zone for which Protected Mode is enabled. By default, IE11 enables Protected Mode for the Internet and Restricted zones but disables it for Local Intranet and Trusted Sites. So, for example, if your page (and/or site) are running in your Local Intranet zone and you're trying to open a new window in the Internet zone, window.open is going to return a null reference. If the page/site which is launching the new window is in the Internet zone, in my experience, window.open will return a reference. So, @ssut's example in jsfiddle is going to work because jsfiddle.com and google.com are probably both in the same zone (I'm assuming the Internet zone).

这篇关于在window对象上调用focus()时遇到IE11的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆