iframe is often used in compound documents. Using jquery to operate iframe can greatly improve efficiency. Here are some basic operations
DOM method:
Parent window operation IFRAME: window.frames["iframeSon"].document
IFRAME operation parent window: window.parent.document
jquery method:
Select all input boxes in the IFRAME in the parent window: $(window.frames["iframeSon"].document).find(":text");
Select all input boxes in the parent window in IFRAME: $(window.parent.document).find(":text");
iframe HTML:
1. Select all radio buttons in the IFRAME in the parent window
$(window.frames["iframe1"].document).find("input[@type=' radio']").attr("checked","true");
2. Select all radio buttons in the parent window in the IFRAME
$(window.parent.document).find("input[@type='radio']") .attr("checked","true");
iframe frame:
$(document.getElementById('iframeId').contentWindow.document.body).htm()
$(document.getElementById('iframeId').contentWindow.document.body).htm()
显示iframe中body元素的内容。
$("#testId", document.frames("iframename").document).html();
$("#testId", document.frames("iframename").document).html();
根据iframename取得其中ID为"testId"元素
$(window.frames["iframeName"].document).find("#testId").html()
$(window.frames["iframeName"].document).find("#testId").html()
作用同上
收集网上的一些示例:
用jQuery在IFRAME里取得父窗口的某个元素的值
只好用DOM方法与jquery方法结合的方式实现了
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框架的:
IE7中测试通过
使用jquery操作iframe
1、内容里有两个ifame
You can use the following statement in frame1 to reference frame2:
self.parent.frames["frame2"];
4. Mutual references between frameworks at different levels
The hierarchy of frames is for top-level frames. When the levels are different, as long as you know the level you are at and the level and name of the other frame, you can easily access each other by using the properties of the window object referenced by the frame, for example:
self.parent.frames["childName"].frames["targetFrameName"];
5. Reference to the top-level frame
Similar to the parent attribute, the window object also has a top attribute. It represents a reference to the top-level frame, which can be used to determine whether a frame itself is a top-level frame, for example:
//Determine whether this frame is a top-level frame
if(self==top){
//dosomething
}