Javascript window.opener不适用于chrome和Opera

Javascript window.opener不适用于chrome和Opera,javascript,window.opener,Javascript,Window.opener,尝试了被接受的答案 使用top.window.opener访问parent.html。运气不好。下面是我的代码 <p>Click the button to write some text to the source (parent) window.</p> <button onclick="openWin()">Open "myWindow"</button> <script> function test1() { ale

尝试了被接受的答案 使用top.window.opener访问parent.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>
parentWindow.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>
单击按钮将一些文本写入源(父)窗口

<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>
打开“我的窗口” 函数test1() { 警报(“测试1”); } 函数openWin() { var myWindow=window.open(“childWindow.html”); }
childWindow.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>
<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>

小孩
函数初始化()
{
试一试{
if(top.window.opener!=null&&!top.window.opener.closed)
{
top.window.opener.test1();
}
}捕获(e){警报(e.description);}
}
从中摘录后,在服务器上尝试了相同的代码。
力帮助。

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

<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>
    if(parent.window.opener != null && ! parent.window.opener)
    {
      parent.window.opener.test1();
    }

希望这能有所帮助。

根据标准,如果省略第二个参数,则该参数应默认为
\u blank
,但所有浏览器可能都不遵循该参数。指定目标,以便您知道它确实会在新窗口中打开,而不会替换当前窗口:

<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>
window.open("childWindow.html", "_blank");

您提供的链接中的
parent
关键字在哪里?为什么要使用
top
?同时使用parent关键字和top。不走运@tomaspatircakha您是否通过Ctrl+F5完全刷新了页面?它可能缓存了不正确的变量。Frames有一个父窗口,而不是单独的窗口。@Guffa,谢谢你的有用评论。但是我不明白你提到的是哪一帧。你能详细说明一下吗?如果页面位于页面中的
框架
iframe
中,那么它有一个父窗口。如果它是作为一个新窗口打开的,那么它就没有父窗口了。@Guffa,谢谢你的回答。我明白你的意思。事实上,如果页面位于框架内,则该页面有一个父级。@Guffa,再次感谢您。恐怕我不明白你的确切意思。你能给我指一下正确的方向吗?我想了解一个页面没有父页面的情况。