window.opener | 没有使用chrome

sre*_*ree 3 html javascript google-chrome

我有两个html页面..我正在从孩子那里调用父窗口.所有的东西都很棒.但是在Chrome中它失败了..我知道原因..

test1.html: -

<html>
<head>
<title>Compose</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<SCRIPT>
function test(){
//alert('');
var win = window.open('../login/test2.html',"","height=700,width=800");
}
function test1(){
alert('test1');
}
</SCRIPT>
</head>
<body>

<input type="button" value="click" onclick="test();" />             
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

test2.html: -

<html>
<head>
<title></title>
<SCRIPT>
function opener1(){
try{
    if(window.opener != null && !window.opener.closed)
    {

    }
    window.opener.test1();
    }catch(e){ alert(e.description);}
}
</SCRIPT>
</head>
<body oncontextmenu="return false"  ondragstart="return false" onload="opener1();">
<h1>Test Page</h1>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

来自test2.html的test1.html中的调用方法无法正常工作..任何解决方案......都认可.谢谢

anu*_*upr 5

只能使用parent变量访问父窗口.对opener1函数的以下修改应该使这成为可能

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

    }catch(e){ alert(e.description);}       
}
Run Code Online (Sandbox Code Playgroud)