
jquery、contentWindow
$("#ii")[0]contentWindow
如果用jquery选择器获得iframe,需要加一个0;
$("#ii")[0]contentWindow$("#dd")val()
可以在得到iframe的window对象后接着使用jquery选择器进行页面 *** 作;
$('#id', windowparentdocument)
2在iframe中调用父页面中定义的方法和变量:
parentmethod
parentvalue
//1、格式:
windowframes["iframe的name值"]documenttitle;
//实例:
windowframes["ifm"]documenttitle;
//2、格式:
var obj=documentgetElementById("iframe的name")contentWindow;
var ifmObj=objdocumenttitle;
//实例:
var obj=documentgetElementById("ifm")contentWindow;
var ifmObj=objdocumenttitle;
//3、格式:
windowparentdocumentgetElementById("父窗口的元素ID")title;
//实例:
windowparentdocumentgetElementById("ifm")title;
//jquery在父窗口中获取iframe中的元素
//1、格式:
$("#iframe的ID")contents()attr("title");//jquery 方法1
//实例:
$("#ifm")contents()attr("title");//jquery 方法1
//2、格式:
$(selector, windowtopdocument);; //jquery 方法2
//实例:
$(document, windowtopdocument)attr("title");//jquery 方法2
//类似的方法
$(selector, windowtopdocument);
$(selector, windowopenerdocument);
$(selector, windowtopframes[0]document);
原理就是先在当前页面中找到你的Iframe对象
var
oframe
=
documentgetElementById("iframe");
再将iframe对象看着是另一个页面的文本对象
var
childDome
=
oframedocumentgetElementById("H");
简洁点的就是:documentgetElementById("iframe")documentgetElementById("H");
或者是:documentgetElementById("Result")contentWindowdocumentgetElementById("h");
以上就是关于如何用javascript 跨域获取iframe子页面的元素信息全部的内容,包括:如何用javascript 跨域获取iframe子页面的元素信息、jquery 怎么获取当前iframe的父元素、jquery在父页面获取iframe子页面的title,怎么获取等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)