![](/img/trans.png)
[英]Trying to call the child window function from parent window after window.open
[英]Child of window.open doesn't call function in parent window
<html>
<head>
<script type="text/javascript">
function openWin()
{
myWindow=window.open('child.html','','width=200,height=100');
}
function callback(){
alert("test");
}
</script>
</head>
<body>
<input type="button" value="Open 'myWindow'" onclick="openWin()" />
</body>
</html>
<html>
<head>
<script type="text/javascript">
window.opener.callback();
</script>
</head>
<body>
</body>
</html>
问题是子页面在FF,IE中而不是在Chrome中调用父页面的回调函数。
任何想法 ?
发生问题是由于Chrome安全性错误。 域,协议和端口必须匹配。 但是从本地文件系统打开页面时也会发生。
从服务器打开页面,应该没有任何问题。
问题可能是chrome如何运行javascript的方式。 Chrome浏览器有时会如此快且早地运行js,甚至DOM还没有准备好进行操作。 在您的child.html中尝试
<script type="text/javascript">
setTimeout(function(){window.opener.callback();}, 100);
</script>
我不确定这是否对您确切,我在chrome上使用jQuery.ready()遇到了此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.