`
lichaobao
  • 浏览: 45355 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

iframe父子窗口间JS方法调用

    博客分类:
  • js
阅读更多

父窗口页面:
<html>
<head>
<script type="text/javascript">
 
function hello(){ 
     alert("parent.html------>I'matparent.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--->I'matchild.html"); 

 
function callParent(){ 

     // parent.functionName();
     parent.hello(); //子窗口掉父窗口hello方法

</script>
</head>
<body>
<input type="button" value="调用父窗口hello方法"onclick="callParent()">
</body>
</html>

0
3
分享到:
评论
2 楼 lichaobao 2014-12-15  
@xiaowanghappy本人没有用过HTML5,求解
1 楼 xiaowanghappy 2014-12-04  
这个必须在一个域下面 跨域的话推荐用html5的postMessage,很好用。

相关推荐

Global site tag (gtag.js) - Google Analytics