IFrame子窗口JS方法互相调用和传参

child1.html和child2.html都是父页面parent.html中的一个子iframe,请看child1.html如何调用child2.html中的方法。


parent.html

[xhtml]  view plain copy
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
  2. <html>  
  3.     <head>  
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.         <meta http-equiv="Content-Style-Type" content="text/css">  
  6.         <meta http-equiv="Content-Script-Type" content="text/javascript">  
  7.         <title>jQuery Cookie Plugin</title>  
  8.     </head>  
  9.     <body>  
  10.         <iframe id="myFrame1" src="child1.html" mce_src="child1.html"></iframe>   
  11.     <iframe id="myFrame2" src="child2.html" mce_src="child2.html"></iframe>  
  12.     </body>  
  13. </html>  


child1.html

[xhtml]  view plain copy
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  4.         <meta http-equiv="Content-Style-Type" content="text/css">  
  5.         <meta http-equiv="Content-Script-Type" content="text/javascript">  
  6.         <title>jQuery Cookie Plugin</title>  
  7.     <mce:script type="text/javascript" src="jquery-1.4.2.js" mce_src="jquery-1.4.2.js"></mce:script>  
  8.     <mce:script type="text/javascript"><!--  
  9.     function test1() {  
  10.         window.parent.document.getElementById("myFrame2").contentWindow.test2();  
  11.     }  
  12.       
  13. // --></mce:script>  
  14.     </head>  
  15.     <body>  
  16.         <input type="button" onclick="test1();" value="test" />  
  17.     </body>  
  18. </html>  


child2.html

[xhtml]  view plain copy
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  4.         <meta http-equiv="Content-Style-Type" content="text/css">  
  5.         <meta http-equiv="Content-Script-Type" content="text/javascript">  
  6.         <title>jQuery Cookie Plugin</title>  
  7.     <mce:script type="text/javascript" src="jquery-1.4.2.js" mce_src="jquery-1.4.2.js"></mce:script>  
  8.     <mce:script type="text/javascript"><!--  
  9.     function test2() {  
  10.         alert("I am your brother");  
  11.     }  
  12.       
  13. // --></mce:script>  
  14.     </head>  
  15.     <body>  
  16.         2  
  17.     </body>  
  18. </html>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值