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
  • 相关阅读:
    javascript之Number
    javascript之window对象
    javascript全局对象
    javascript之尺寸,位置,溢出
    javascript之DOM操作
    javascript之全局函数
    javascript之Error
    javascript之url转义escape()、encodeURI()和decodeURI()
    javascript之Boolean
    javascript之Arguments
  • 原文地址:https://www.cnblogs.com/pecool/p/9192679.html
Copyright © 2011-2022 走看看