javascript window.open() 仍然返回 null

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11339600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 12:50:47  来源:igfitidea点击:

window.open() still returns null

javascript

提问by user1501905

I am using IE8 on Windows 7. Referred to several threads and understand that in IE8 when I am using window.open to popup a new window, the JavaScript window.open is returning null value.

我在 Windows 7 上使用 IE8。参考了几个线程并了解在 IE8 中,当我使用 window.open 弹出一个新窗口时,JavaScript window.open 返回空值。

If I run IE as administrator or disable the protected mode, I see the window.open returns the expected object.

如果我以管理员身份运行 IE 或禁用保护模式,我会看到 window.open 返回预期的对象。

I am looking out for a solution apart from the options mentioned above. For such a small feature (opening a popup) I cannot ask customer to run IE as administrator or disable the protected mode.

我正在寻找除上述选项之外的解决方案。对于这么小的功能(打开弹出窗口),我不能要求客户以管理员身份运行 IE 或禁用保护模式。

If there is any work around, please let me know. It will be a great help.

如果有任何解决办法,请告诉我。这将是一个很大的帮助。

Primarily, I want to make sure that only one window is opened when user clicks multiple times on the link and give the focus to the window which is already open. To achieve this I need to get the object from window.open so that I can check if the window is already open and give the focus to the already opened window. Otherwise open a new window.

首先,我想确保当用户多次点击链接时只打开一个窗口,并将焦点放在已经打开的窗口上。为了实现这一点,我需要从 window.open 获取对象,以便我可以检查窗口是否已经打开并将焦点放在已经打开的窗口上。否则打开一个新窗口。

回答by Pintu Paraliya

For IE10, window.open returns a NULL reference object if Enable Protected Mode is checked under Internet Options->Security->Security Level for this zone and the ZONE is different i.e. in my case local file opening a popup from Intranet.

对于 IE10,如果在 Internet 选项-> 安全性-> 安全级别为此区域选中启用保护模式,并且该区域不同,即在我的情况下本地文件打开来自 Intranet 的弹出窗口,则 window.open 返回一个 NULL 引用对象。

window.open returns a reference object even if Enable Protected Mode is checked when yoursite.com opens someothersite.com in popup window i.e. Internet->Internet

即使在 yoursite.com 在弹出窗口(即 Internet->Internet)中打开 someothersite.com 时选中启用保护模式,window.open 也会返回参考对象

回答by Antguider

You can use window.showModalDialogas a alternative or replacement for window.openmethod.

您可以使用window.showModalDialog作为window.open方法的替代或替代。

It is more secure then window.open. It will not allow user clicking the Parent page.

它比window.open 更安全。它不允许用户单击父页面。

Example Usage:

示例用法:

var myFeatures = "dialogWidth:1060px;dialogHeight:550px;resizable:yes";

window.showModalDialog(url,window,myFeatures);
       //Here window is an object, no need to assign or declare.

If you want more detail explanation see Here. //Fifth Question.

如果您想了解更多详细说明,请参阅此处。//第五个问题。