首页 > 技术文章 > HTML中嵌套的子frame如何访问父页面中的函数?

pecool 2018-06-17 13:09 原文

 

我解决的办法,在父页面写了个函数,然后在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中测试通过

推荐阅读