zoukankan      html  css  js  c++  java
  • js实现iframe跨页面调用函数的方法

    本文实例讲述了js实现iframe跨页面调用函数的方法。分享给大家供大家参考。具体实现方法如下:

    在项目中难免会遇到这样一个问题就是页面引入了IFrame并且需要父页面调用子页面函数或者子页面需要调用父页面函数。比如说:现在有两个页面parent.html和child.html。其中parent.html中含有IFrame并且IFrame指向child.html。现在需要在parent.html/child.html中调用child.html/parent.html的一个js方法。   

    具体的代码实现如下:

    parent.html父页面:

    <html> 
    <head> 
    <script type="text/javascript"> 
      function parent_click(){ 
        alert("来自父页面"); 
      } 
    </script> 
    </head> 
    <body> 
      <input type="button" value="调用本页面函数" onclick="parent_click();" /> 
      <input type="button" value="调用子页面函数" onclick='window.frames["childPage"].child_click();' /> 
      <iframe id="childPage" name="childPage" src="inner.html" width="100%" frameborder="0"></iframe> 
    </body> 
    </html>

    child.html子页面:

    <html> 
    <head> 
    <script type="text/javascript"> 
      function child_click(){ 
        alert("调用的子页面函数"); 
      } 
    </script> 
    </head> 
    <body> 
      <input type="button" value="调用父页面函数" onclick='parent.window.parent_click();' /> 
      <input type="button" value="调用本页面函数" onclick="child_click();" /> 
    </body> 
    </html>
  • 相关阅读:
    Mysql5.5安装
    JVM内存管理
    jquery, js轮播图插件Swiper3
    Redis基本结构
    ArcGIS10.1发布WFS-T服务
    ArcGIS10.1如何将数据库注册到ARCSERVER服务器
    转:Oracle密码过期,取消密码180天限制
    oracle数据库导入导出命令
    转载:oracle11G 已开启监听,但远程连接依旧无监听解决过程
    Xcode group
  • 原文地址:https://www.cnblogs.com/qiantao/p/12383538.html
Copyright © 2011-2022 走看看