父窗口调用子窗口的方法
myFrame.window.childAction();
注: myFrame : iframe 的name属性值
childAction() : 子窗口中定义的childAction方法
子窗口调用父窗口中的方法
parent.parentAction();
注: parentAction() : 父窗口中定义的parentAction方法
举例说明:
父窗口代码:
<html>
<head>
<script type="text/javascript">
function parentAction() {
alert("parent function");
}
function callChild()
{
myFrame.window.childAction();
}
</script>
</head>
<body>
<input type=button value="调用子窗口中的方法" onclick="callChild()">
<iframe name="myFrame" src="child"></iframe>
</body>
</html>
子窗口代码:
<html>
<head>
<script type="text/javascript">
function childAction() {
alert("child function");
}
function callParent() {
parent.parentAction();
}
</script>
</head>
<body>
<input type=button value="调用父窗口中的方法" onclick="callParent()">
</body>
</html>