带有 window.opener 的 IE 中的 JavaScript 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7648231/
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
JavaScript issue in IE with window.opener
提问by htm11h
I am trying to use the following JavaScript to check if a popup page is still open.
我正在尝试使用以下 JavaScript 来检查弹出页面是否仍处于打开状态。
The parent page (calling page to open popup) is open but this code continues to fail. I am calling it from an aspx popup page that has a masterpage inside another masterpage. So the click event that eventually calls this script is an Edit Link in a Gridview in a content Placeholder which is in the upper most master page content Placeholder, not sure if that has anything to do with it. The script fires but it does not see the parent page as open and not closed.
父页面(调用页面打开弹出窗口)已打开,但此代码继续失败。我从一个 aspx 弹出页面调用它,该页面在另一个母版页中有一个母版页。因此,最终调用此脚本的单击事件是内容占位符中 Gridview 中的编辑链接,该内容占位符位于最上方的母版页内容占位符中,不确定是否与此有关。脚本会触发,但它不会将父页面视为打开且未关闭。
if (window.opener != null && !window.opener.closed) {
alert(window.opener);
var val = window.opener.parentFunc(a);
alert(a);
}
This is an IE only problem, Firefox can identify the window.opener
page. Tried multiple versions of IE all had issues, Firefox and Opera work though.
这是 IE 唯一的问题,Firefox 可以识别window.opener
页面。尝试了多个版本的 IE 都有问题,但 Firefox 和 Opera 工作正常。
I actually used this alert statement....
我实际上使用了这个警报声明....
alert(window.opener);
In IE returns Undefined.
在 IE 中返回未定义。
In Firefox returned ObjectWindow.
在 Firefox 中返回 ObjectWindow。
采纳答案by htm11h
I got this to work by sending the script from VB.net like this....
我通过像这样从 VB.net 发送脚本来使这个工作......
Dim BrowserSettings As String = "status=no,toolbar=no, scrollbars =yes,menubar=no,location=no,resizable=no," & "titlebar=no, addressbar=no, width=650 ,height=800"
Dim URL As String = "testNewPage.aspx"
Dim scriptText1 As String = ("<script>javascript: var w = window.open('" & URL & "','_blank','" & BrowserSettings & "'); </script>")
ScriptManager.RegisterStartupScript(Me, GetType(Page), "ClientScript1", scriptText1, False)here
This isn't exactly what I wanted, but it seems to be working except now the popup page is not on top. Need to figure that part out.
这不是我想要的,但它似乎正在工作,除了现在弹出页面不在顶部。需要弄清楚那部分。
I have been trying to apply focus, doesn't seem to work. Also, tried a modaless popup, that works but I lose the reference to the open window then.
我一直在尝试应用焦点,似乎不起作用。另外,尝试了一个无模式的弹出窗口,它有效,但我失去了对打开窗口的引用。
回答by Garrett Vlieger
I believe this is a security restriction in IE. Take a look at this thread and see if it answers your problem:
我相信这是 IE 中的安全限制。看看这个线程,看看它是否能解决你的问题:
回答by Red Peter
function getParentWindow(){
var father = window.opener;
if(father == undefined) {
father=window.dialogArguments
}
return father;
}