iframe父子窗口间JS方法调用

<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">

function hello(){
     alert("father.html");
}

function callChild()
{
     //myFrame是iframe的name
     //myFrame.window.functionName();
     myFrame.window.hello();  //父窗口掉子窗口hello方法
}
</script>
</head>

<body>
<input type="button" value="调用子窗口hello方法" onclick="callChild()">
<iframe name="myFrame" src="child.html"></iframe>
</body>
</html>
========================================================================
<html>
<head>
<script type="text/javascript">
function hello()
{
     alert("child.html");
}

function callParent(){
     // parent.functionName();
     parent.hello(); //子窗口掉父窗口hello方法
}
</script>
</head>
<body>
<input type="button" value="调用父窗口hello方法"onclick="callParent()">
</body>
</html>

转自:http://lichaobao.iteye.com/blog/2163088

你可能感兴趣的:(iframe)