Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.opener |不在镀铬中工作_Javascript_Html_Google Chrome - Fatal编程技术网

Javascript window.opener |不在镀铬中工作

Javascript window.opener |不在镀铬中工作,javascript,html,google-chrome,Javascript,Html,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

我有两个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>

组成
功能测试(){
//警报(“”);
var win=window.open('../login/test2.html','',“高度=700,宽度=800”);
}
函数test1(){
警报(“test1”);
}
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>

函数opener1(){
试一试{
if(window.opener!=null&&!window.opener.closed)
{
}
window.opener.test1();
}捕获(e){警报(e.description);}
}
测试页

从test2.html调用test1.html中的方法无效..任何解决方案..感谢..

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

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

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

代码对我来说似乎很好。如果捕获到异常,可以将其记录到控制台,以获取错误信息。确保test1.html和test2.html的域匹配,否则将出现安全异常。

您可以尝试我的代码:

window.opener.document.location.href = url;
这将同时适用于IE和Chrome

window.opener.location.href = 'test.html';
这将打开“test.html”页面

一旦父窗口打开,您就可以关闭它


如果我的答案有效,请不要忘记将其标记为正确。

这是因为
windows
对象的
opener
属性在iPadChrome

等设备上为空。为什么
家长参与了此操作?嗨,anurpur仍然是同一个pblm。。警报表示未定义,因为您想访问调用第二个窗口(test2.html)的窗口(test1.html)的函数。因此test1.html是test2.html的父窗口。这就是javascript的操作方式。简单调用窗口指的是当前窗口。如果警报表示未定义,则将调用catch块中的警报。你能粘贴控制台上显示的错误吗?很有意思。这方面似乎没问题。您是否100%确定对test2.html中的opener1函数进行了更改?错误消息是:阻止原点为“null”的帧访问跨原点帧,因此这意味着域与您的父子窗口不匹配。如果从文件系统中打开html,这也不起作用。我在Windows7下使用Chrome64,并且“window.opener”一点也不为空。