简体   繁体   English

IE中带有window.opener的JavaScript问题

[英]JavaScript issue in IE with window.opener

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. 我是从在另一个母版页中具有母版页的aspx弹出页面调用它的。 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. 因此,最终调用该脚本的click事件是位于内容占位符中Gridview中的“编辑链接”,该占位符位于母版页的最上方内容占位符中,不确定是否与此有关。 The script fires but it does not see the parent page as open and not closed. 脚本将触发,但它不会将父页面视为打开且未关闭。

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. 这是仅IE的问题,Firefox可以识别window.opener页面。 Tried multiple versions of IE all had issues, Firefox and Opera work though. 尝试使用多个版本的IE都存在问题,但是Firefox和Opera可以正常工作。

I actually used this alert statement.... 我实际上使用了此警报声明。

alert(window.opener);

In IE returns Undefined. 在IE中返回未定义。

In Firefox returned ObjectWindow. 在Firefox中返回了ObjectWindow。

function getParentWindow(){
    var father = window.opener;
    if(father == undefined) {
       father=window.dialogArguments
    }

    return father;  
}

I believe this is a security restriction in IE. 我相信这是IE中的安全限制。 Take a look at this thread and see if it answers your problem: 看一下这个线程,看看它是否可以解决您的问题:

http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/thread/0c014e78-8d35-4df3-93da-7f6a30b4ed8b http://social.msdn.microsoft.com/Forums/zh-CN/iewebdevelopment/thread/0c014e78-8d35-4df3-93da-7f6a30b4ed8b

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. 另外,尝试了一个有模态的弹出窗口,该弹出窗口可以工作,但随后我丢失了对打开的窗口的引用。

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

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