zoukankan      html  css  js  c++  java
  • HTML中嵌套的子frame如何访问父页面中的函数?

    我解决的办法,在父页面写了个函数,然后在frame页面调用父页面的函数,具体代码如下:

    父:function a(){}

    子frame:window.parent.a();

    问题迎刃而解,2020/04/20日补记:如果frame中的页面和父页面不同域。则需要进行跨域实现js代码互相调用。这种情况,往document.domain方向去调查。

     https://www.jb51.net/article/39486.htm

    参考1:http://m.php.cn/article/383528.html

    参考2:https://www.jb51.net/article/116273.htm

    附件:

    DOM方法:
    父窗口操作IFRAME:window.frames["iframeSon"].document
    IFRAME操作父窗口: window.parent.document

    jquery方法:
    在父窗口中操作 选中IFRAME中的所有输入框: $(window.frames["iframeSon"].document).find(":text");
    在IFRAME中操作 选中父窗口中的所有输入框:$(window.parent.document).find(":text");
    iframe框架的HTML:<iframe src="test.html" id="iframeSon" width="700″ height="300″ frameborder="0″ scrolling="auto"></iframe>

    1.在父窗口中操作 选中IFRAME中的所有单选钮
    $(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

    2.在IFRAME中操作 选中父窗口中的所有单选钮
    $(window.parent.document).find("input[@type='radio']").attr("checked","true");
    iframe框架的:

    <iframe src="test.html" id="iframe1″ width="700″ height="300″ frameborder="0″ scrolling="auto"></iframe>

    1.在父窗口中操作 选中IFRAME中的所有单选钮
    $(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

    2.在IFRAME中操作 选中父窗口中的所有单选钮
    $(window.parent.document).find("input[@type='radio']").attr("checked","true");
    iframe框架的:<iframe src="test.html" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"></iframe>
    IE7中测试通过

    Best Regards
  • 相关阅读:
    jQuery before 和 after
    pm2常用的命令
    git 常见命令
    Number 和 parseInt 区别
    枚举创建单例模式 安全 而且利用反射也读不到
    spring 的数据库工具类 JDBCTemplate
    阿里druid数据库连接及配置文件
    java C3P0连接数据库
    JDBC利用.properties文件连接数据库
    JDBC工具类的使用
  • 原文地址:https://www.cnblogs.com/pecool/p/9192679.html
Copyright © 2011-2022 走看看