JavaScript window.opener调用父函数 [英] JavaScript window.opener call parent function
本文介绍了JavaScript window.opener调用父函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从子窗口调用父级中定义的javascript函数。我有两个这样的文件:
I am trying to call a javascript function defined in a parent from a child window. I have two files like this:
父母:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function foo () {
alert ("Hello from parent!");
}
function doStuff () {
var w = window.open("testa.html");
}
</script>
</head>
<body>
<input type="button" value="open" onClick="doStuff();" />
</body>
</html>
和孩子:
<html>
<head>
<title>Test A</title>
<script type="text/javascript">
function get() {
window.opener.foo();
}
</script>
</head>
<body>
<input type="button" value="Call Parent" onClick="get();" />
</body>
</html>
在我的生命中,我不能从子进程调用函数foo。我认为这应该可以使用window.opener对象,但我似乎无法使这个工作。有什么建议吗?
I can not, for the life of me, call the function foo from the child process. I thought this should be possible with the window.opener object, but I can not seem to make this work. Any suggestions?
推荐答案
确保您通过http://访问此内容,以便通过相同的原始策略,您可以访问孩子如果您只是使用file://,它将无法工作。
Ensure you are accessing this via http:// so the Same origin policy passes and you can access opener from the child. It won't work if you're just using file://.
这篇关于JavaScript window.opener调用父函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文