1

尝试了此链接的已接受答案, 使用 top.window.opener 访问 parent.html .no lucky 。下面是我的代码

父窗口.html

<p>Click the button to write some text to the source (parent) window.</p>

<button onclick="openWin()">Open "myWindow"</button>

<script>
function test1()
{
    alert("test1");
}
function openWin()
{
var myWindow = window.open("childWindow.html");

}
</script>

</body>
</html>

childWindow.html

<HTML>
<HEAD>
  <title>Child</title>

<SCRIPT type="text/javascript" LANGUAGE="javascript">

function Initialize()
{
     try{
        if(top.window.opener != null && !top.window.opener.closed)
        {
          top.window.opener.test1();
        }

    }catch(e){ alert(e.description);}  


}
</script>
</HEAD>
<BODY onload="Initialize()">

</BODY>
</HTML>

遵循此链接的摘录后,在服务器上尝试了相同的代码。点帮助。

4

2 回答 2

2

根据标准,第二个参数应该默认为_blankif 它被省略,但所有浏览器可能不会遵循这一点。指定目标,以便您知道它确实在新窗口中打开并且不会替换当前窗口:

window.open("childWindow.html", "_blank");
于 2014-04-12T13:42:26.330 回答
0

我想你想做的是parent.window.opener

    if(parent.window.opener != null && ! parent.window.opener)
    {
      parent.window.opener.test1();
    }

希望这可以帮助。

于 2014-04-12T13:27:51.740 回答