在IFrame中查找IFRAME中的元素的方式

简介: 下面是内部iframe找外部mainFrame的情况 var websiteSearchButton = window.parent.parent.document.getElementById('mainFrame')      .contentWindow.document.getElementById("webresource-search-button"); iframe中1
下面是内部iframe找外部mainFrame的情况
 var websiteSearchButton = window.parent.parent.document.getElementById('mainFrame')
     .contentWindow.document.getElementById("webresource-search-button"); 

iframe中
1、子页面找符页面中的元素
$(window.parent.document).find(id);
2、父页面--->子页面中的
$(id).contents().find(元素id).find(元素id);
3、子页面--->爷爷界别的页面
$(window.top.document).find(id);


例子:
var body2 = jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents().find("body").html();
console.log(body2);

1、window.top.document.getElementById("eWebEditor2")     :表示在一个iframe中找最顶层中的document,然后在找最外层的document中的eWebEditor2的这个元素(上例子表示的是一个iframe),

2、jQuery(window.top.document.getElementById("eWebEditor2"))    表示把eWebEditor2这个iframe转成jQuery对象

3、jQuery(window.top.document.getElementById("eWebEditor2")).eq(0)   表示取到第一个元素

4、.contents().find("#eWebEditor")    表示取eWebEditor2这个iframe中eWebEditor这个元素(这里这个元素表示的又是一个iframe)

5、jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents()    表示eWebEditor这个iframe中的内容

6、jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents().find("body")   表示取到eWebEditor这个内容中的body元素

7、最终 jQuery(window.top.document.getElementById("eWebEditor2")).eq(0).contents().find("#eWebEditor").contents().find("body").html();    表示body中的内容


目录
相关文章
|
JSON JavaScript 数据格式
jQuery操作页面元素属性和内容
jQuery操作页面元素属性和内容
52 0
|
4月前
|
JavaScript 前端开发 API
快速实现 iframe 嵌套页面
【6月更文挑战第22天】快速实现 iframe 嵌套页面
|
10月前
|
JavaScript
原生js插入HTML元素
原生js插入HTML元素
100 1
|
11月前
|
JavaScript
iframe子页面获取父页面元素,或父页面获取iframe子页面的元素
iframe子页面获取父页面元素,或父页面获取iframe子页面的元素
|
JavaScript 前端开发
js内联外联样式的获取,父页面获取iframe框架元素返回null
js内联外联样式的获取,父页面获取iframe框架元素返回null
|
前端开发
CSS中有哪些隐藏页面元素的方法?
CSS中有哪些隐藏页面元素的方法?
97 0
|
JavaScript
jQuery(二)修改元素、查找元素
jQuery(二)修改元素、查找元素
269 0
jQuery(二)修改元素、查找元素
|
前端开发
iframe的运用---特别是获取父子页面的元素
iframe的运用---特别是获取父子页面的元素
497 0
|
Web App开发 移动开发 JavaScript
iframe的一些记录
首要要做配置操作,配置两个域名,我这里使用的是Apache。附件中的demo1和demo2
iframe的一些记录