适用于Firefox 20.0.1和IE 10.0.9200.16442,但两个输入元素都无法在Chrome 26.0.1410.64 m中使用
Chrome控制台显示了这一点:
未捕获的TypeError:对象[对象全局]的属性“说”不是函数
======================== 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()" />
答案 0 :(得分:0)
我的原型bla bla错了,但是从你的iframe调用时看到差异
function callParent() {
console.log(window.say); //childs.say function
console.log(top.say); //parents.say function
console.log(self.say, this.parent.say); //more fun!
//window.parent.say();
}