Summary of several methods for jquery to operate iframe _ jquery

Source: Internet
Author: User
This article provides a detailed summary of several methods for using jquery to operate iframe. For more information, see iframe, using jquery to operate iframe can greatly improve efficiency. Here we collect some basic operations

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:

Certificate (document.getelementbyid('iframeid'{.content}document.body}.htm ()
Certificate (document.getelementbyid('iframeid'{.content}document.body}.htm ()

Displays the content of the body element in iframe.

$ ("# TestId", document. frames ("iframename" 2.16.document).html ();
$ ("# TestId", document. frames ("iframename" 2.16.document).html ();

Obtain the "testId" element based on iframename.

$ (Window. frames ["iframeName" cmd.doc ument). find ("# testId" cmd.html ()
$ (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 </P> <P> $ ("# mainiframe "). contents (). find ("someID" ).html () html or $ ("# mainiframe "). contains (). find ("someID "). text () value </P> <STRONG> 3. In the parent window, select all radio buttons in IFRAME. <BR> </STRONG> $ (window. frames ["iframe1" 2.16.doc ument ). find ("input [@ type = 'Radio ']"). attr ("checked", "true"); </P> <P> you can still use the find method to select an id. <BR> $ (window. frames ["I Frame1 "example .doc ument ). find ("# id ") </P> <STRONG> 4. 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 () </P> <BR> <STRONG> using JavaScript to manipulate iframe </STRONG> </P> <P> mutual reference between frameworks </P> <P> all frames on a page are provided as properties of the window object in the form of a set, example: window. frames indicates the set of all frames on the page. Slice objects are similar. The difference is that these sets are the attributes of document. Therefore, to reference a sub-framework, you can use the following syntax: </P> <P> window. frames ["frameName"]; </P> <P> window. frames. frameName </P> <P> window. frames [index] </P> <P> the window can also be replaced or omitted with self. If frameName is the first frame on the page, the following statements are equivalent: </P> <P> self. frames ["frameName"] </P> <P> self. frames [0] </P> <P> frames [0] </P> <P> frameName </P> <P> each frame corresponds to an HTML page, therefore, this framework is also an independent browser window, which has all the properties of the window. The so-called reference to the framework is the reference to the window object. With this window object, you can easily perform operations on the pages. For example, you can write data to the page by using the plain Doc ument object, or use the window. location attribute to change pages in the framework. </P> <P> The following describes the mutual references between frameworks of different levels: </P> <STRONG> 1. references from the parent framework to the Child Framework </STRONG> </P> <P> after understanding the above principles, it is very easy to reference the child framework from the parent framework, that is: </P> <P> window. frames ["frameName"]; </P> <P> references the sub-framework named frameName on the page. 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: </P> <P> window. frames ["frameName"]. frames ["frameName2"]; </P> <P> in this way, the second-level sub-framework can be referenced, and so on. </P> <STRONG> 2. references from the Child Framework to the parent framework </STRONG> </P> <P> 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> <STRONG> 3. reference between sibling frameworks </STRONG> </P> <P> If the two frameworks share the same child framework, they are called sibling frameworks, and mutual reference can be achieved through the parent framework, for example, a page contains two sub-frameworks: </P> <frameset rows = "50%, 50% "> </P> <frame src =" 1.html "name =" frame1 "/> </P> <frame src =" 2.html "name = "frame2"/> </P> </frameset> </P> <P> In frame1, you can use the following statement to reference frame2: </P> <P> self. parent. frames ["frame2"]; </P> <STRONG> 4. mutual reference between frameworks of Different Levels </STRONG> </P> <P> 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: </P> <P> self. parent. frames ["childName"]. frames ["targetFrameName"]; </P> <STRONG> 5. the reference to the top-level framework </STRONG> </P> <P> 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: </P> <P> // determine whether the framework is a top-level framework </P> <P> if (self = top) {</P> <P> // dosomething </P> <P>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.