实现 iframe 子页面调用父页面中的js方法

父页面:index.html(使用iframe包含子页面child.html)
  1. <html>  
  2. <head>  
  3. <script type="text/javascript">  
  4. <!--  
  5. function toshow(msg){  
  6.     alert("这里是父页面:"+msg);  
  7. }  
  8. // -->  
  9. </script>  
  10. </head>  
  11. <body>  
  12. <iframe background="blue" src="child.html" mce_src="child.html"></iframe>  
  13. </body>  
  14. </html>  

 

子页面child.html(调用父页面toshow方法) 

 

 

    1. <html>  
    2. <head>  
    3. <script type="text/javascript">  
    4. <!--  
    5. function doparent(){  
    6. window.parent.toshow('ccccchild');  
    7. }  
    8. // -->  
    9. </script>  
    10. </head>  
    11. <body>  
    12. This is child frame!!  
    13. <input type="button" value="请点击" onclick='doparent()'></input>  
    14. </body>  

 

posted on 2013-11-04 10:54  水行者  阅读(1444)  评论(0编辑  收藏  举报

导航