Iframe is often used in composite documents. Using jquery to operate iframe can greatly improve efficiency. Here we collect some basic operations. For more information, see
DOM method:
Parent window operation IFRAME: window. frames ["iframeSon" mirror.doc ument
IFRAME operation parent window: paipaiparent.doc ument
Jquery method:
In the parent window, select all input boxes in IFRAME: $ (window. frames ["iframeSon" ].doc ument). find (": text ");
In the IFRAME field, select all input boxes in the parent window: Response (w.w.parent.doc ument). find (": text ");
HTML of the iframe framework:
1. In the parent window, select all radio buttons in IFRAME.
$ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
2. in IFRAME, select all radio buttons in the parent window
Vertex (w.w.parent.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
Iframe framework:
The Code is as follows:
Collect several methods to obtain elements in iframe using Jquery:
The Code is as follows:
Certificate (document.getelementbyid('iframeid'{.content}document.body}.htm ()
Displays the content of the body element in iframe.
The Code is as follows:
$ ("# TestId", document. frames ("iframename" 2.16.document).html ();
Obtain the "testId" element based on iframename.
The Code is as follows:
$ (Window. frames ["iframeName" cmd.doc ument). find ("# testId" cmd.html ()
Same as above
Some examples of online collection:
Use jQuery to obtain the value of an element in the parent window in IFRAME.
We had to use the DOM method and jquery method to achieve this.
1. In the parent window, select all radio buttons in IFRAME.
$ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
2. in IFRAME, select all radio buttons in the parent window
Vertex (w.w.parent.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
Iframe framework:
IE7 passed the test
Use jquery to operate iframe
1. The content contains two ifame
In leftiframe, jQuery changes the src code of mainiframe:
$ ("# Mainframe", parent.doc ument. body). attr ("src", "http://www.jb51.net ")
2. If the content contains an ifame with the ID of mainiframe
</Ifame> <BR> ifame contains a someID <BR> <p id = "someID"> you want to get this content </p> <BR> get someID content <BR> $ ("# mainiframe "). contents (). find ("someID" ).html () html or $ ("# mainiframe "). contains (). find ("someID "). text () value </P> <P> 3. In the parent window, select all radio buttons in IFRAME. <BR> $ (window. frames ["iframe1" 2.16.doc ument ). find ("input [@ type = 'Radio ']"). attr ("checked", "true"); <BR> you can still use the find method to select an id. <BR> $ (window. frames ["iframe1" 2.16.doc ument ). find ("# Id ") <br> 4. As shown above <BR> content of someID in the jQuery operation mainiframe in leftiframe <BR> $ ("# mainframe", parent.doc ument. body ). contents (). find ("someID" ).html () or $ ("# mainframe", parent.doc ument. body ). contents (). find ("someID "). val () <br> <STRONG> using JavaScript to manipulate iframe <BR> </STRONG> mutual reference between frames <BR> all frames on a page act as window objects in the form of a set. attribute, example: window. frames indicates the set of all frames on the page. This is similar to form objects, link objects, and image objects. The difference is that these sets are the attributes of document. Therefore, to reference a sub-framework, you can use the following syntax: <BR> window. frames ["frameName"]; <BR> window. frames. frameName <BR> window. frames [index] <BR> the window can also be replaced or omitted by self. If frameName is the first frame in the page, the following statements are equivalent: self. frames ["frameName"] <BR> self. frames [0] <BR> frames [0] <BR> frameName <BR> each framework corresponds to an HTML page. Therefore, this framework is also an independent browser window, it has all the properties of the window. The so-called reference to the framework is the reference to the window object. With this windowless object, you can easily perform operations on the page. For example, you can use the volume upload Doc ument object to write data to the page, and use the window. location attribute to change pages in the framework. </P> <STRONG> The following describes the mutual references between frameworks of different levels: <BR> </STRONG> 1. references from the parent framework to the Child Framework <BR> after understanding the above principles, it is very easy to reference the child framework from the parent framework, I .e.: <BR> window. frames ["frameName"]; <BR> in this way, the sub-framework named frameName in the page is referenced. If you want to reference the sub-framework in the sub-framework, the referenced framework is actually the nature of the window object, which can be implemented as follows: <BR> window. frames ["frameName"]. frames ["frameName2"]; <BR> the second-level sub-framework is referenced, and so on. </P> <P> 2. references from the Child Framework to the parent framework <BR> each window object has a parent attribute, indicating its parent framework. If the framework is already a top-level framework, window. parent also indicates the framework itself. </P> <P> 3. reference between sibling frameworks <BR> If the two frameworks are the same as the Child frameworks of the same framework and they are called sibling frameworks, mutual reference can be achieved through the parent framework. For example, a page contains two child frameworks: <BR> <frameset rows = "50%, 50% "> <BR> <frame src =" 1.html "name =" frame1 "/> <BR> <frame src =" 2.html "name =" frame2 "/> <BR> </frameset> <BR> In frame1, you can use the following statement to reference frame2: <BR> self. parent. frames ["frame2"]; </P> <P> 4. mutual reference between frameworks of Different Levels <BR> the framework layers are for top-level frameworks. When the layers are different, you only need to know your own layers and the layers and names of another framework, and use the window object properties referenced by the Framework to easily implement mutual access. For example: <BR> self. parent. frames ["childName"]. frames ["targetFrameName"]; </P> <P> 5. the reference to the top-level framework <BR> is similar to the parent attribute. The window object also has a top attribute. It indicates a reference to the top-level framework, which can be used to determine whether a framework itself is a top-level framework. For example: <BR> // determine whether the framework is a top-level framework <BR> if (self = top) {<BR> // dosomething <BR>}