javascript window.opener 在 Internet Explorer 上未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23562044/
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
window.opener is undefined on Internet Explorer
提问by Shubh
When I am trying to access an element of my Parent window from a Pop-up window, I am getting window.opener
as undefined.
当我试图从弹出窗口访问我的父窗口的元素时,我变得window.opener
未定义。
var opener = window.opener;
if(opener)
{
console.log("opener element found");
var elem = opener.$('.my-parent-element');
if (elem) {
console.log("parent element found");
elem.show();
}
}
Here opener
is undefined. Am I doing something wrong?
这里opener
是未定义的。难道我做错了什么?
I have tried parent.window.opener
/ window.top
/ window.top.document.body
etc., but it doesn't help either. It works fine in other browsers.
我试过parent.window.opener
/ window.top
/window.top.document.body
等,但它也无济于事。它在其他浏览器中运行良好。
I have see the question Window Opener Alternative, but I cannot change opening my popup with showModalDialog
right away. Probably, this would be last option.
我看到了Window Opener Alternative问题,但我无法立即更改打开弹出窗口的方式showModalDialog
。也许,这将是最后的选择。
回答by dpalacio
I had the same problem and it was due to Internet Explorer Security Options, in particular because my popup was going to an External website (Internet area) and the parent was an internal page (Intranet area). The "Protected Mode" was only activated for the "Internet". I activated it for the "Local intranet" and now it works.
我遇到了同样的问题,这是由于 Internet Explorer 安全选项,特别是因为我的弹出窗口将转到外部网站(Internet 区域)而父页面是内部页面(Intranet 区域)。“保护模式”仅针对“互联网”激活。我为“本地内联网”激活了它,现在它可以工作了。
To find this option in IE:
要在 IE 中找到此选项:
- Go to Internet Options
- Security tab
- Click on "Internet" or "Local intranet" icon
- Check or uncheck the option "Enable Protected Mode"
- Restart IE
- 转到 Internet 选项
- 安全选项卡
- 单击“Internet”或“本地 Intranet”图标
- 选中或取消选中“启用保护模式”选项
- 重启浏览器
回答by Andrei
You can use the showModalDialog
function and pass arguments to it, if the browser used is IE. Simply pass window
object as an argument.
如果使用的showModalDialog
浏览器是 IE,您可以使用该函数并将参数传递给它。只需将window
对象作为参数传递。
After that you can access the arguments from the modal window using dialogArguments
.
之后,您可以使用dialogArguments
.
More details can be found in the documentation here: http://msdn.microsoft.com/en-us/library/ms533723%28VS.85%29.aspx
可以在此处的文档中找到更多详细信息:http: //msdn.microsoft.com/en-us/library/ms533723%28VS.85%29.aspx
Example of retrieve:
检索示例:
window.showModalDialog(theURL, window);
//in the modal dialog you can use this to retrieve the window.
var openerWindow = window.dialogArguments;