它适用于 Firefox 20.0.1 和 IE 10.0.9200.16442,但两个输入元素都不适用于 Chrome 26.0.1410.64 m
Chrome 控制台显示了这一点:
未捕获的类型错误:对象 [对象全局] 的属性“说”不是函数
=========================main.html=======================
function say() {
alert("parent.html------>I'm at parent.html");
}
function callChild()
{
var ifrm = document.getElementById("myFrame");
ifrm.contentWindow.say();
}
< input type=button value="invoke say() in the child.html" onclick="callChild()" />
< iframe id="myFrame" name="myFrame" src="child.html" />
========================child.html=======================
function say()
{
alert("child.html--->I'm at child.html");
}
function callParent() {
window.parent.say();
}
< input type=button value="invoke function say() in the parent.html" onclick="callParent()" />