Jquery gets several methods of IFRAME elements. Javascript jquery gets the element, content, or ID of IFRAME, and vice versa!
Several methods for obtaining elements in IFRAME through query
Obtain the elements of the parent page on the IFRAME subpage
The Code is as follows:
$ ('# Objid', parent.doc ument );
// Get it done...
Obtain the element of the IFRAME subpage on the parent page.
The Code is as follows:
$ ("# Objid", document.frames('iframename'assist.doc ument)
Certificate (document.getelementbyid('iframeid'}.content?#document.body=.html ()
Displays the content of the Body element in IFRAME.
$ ("# 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 ()
Use JS or jquery to access IFRAME on the page, and be compatible with IE/FF
Note: pages in the framework cannot be cross-origin!
Assume there are two pages in the same domain.
The index.html file contains an IFRAME:
XML/html code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> homepage </title>
</Head>
<Body>
<IFRAME src = "iframe.html" id = "koyoz" Height = "0" width = "0"> </iframe>
</Body>
</Html>
Iframe.html content:
XML/html code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> iframe.html </title>
</Head>
<Body>
<Div id = "test"> www.koyoz.com </div>
</Body>
</Html>
1. Execute JS access in index.html:
JavaScript code
Document.getelementbyid('koyoz'{.content}w.doc ument. getelementbyid
('Test'). style. Color = 'red'
Access the IFRAME page with the ID 'koyoz' in index.html and obtain
Object, and set its color to red.
This code has been tested and supports IE/Firefox.
2. Access through jquery in index.html:
JavaScript code
$ ("# Koyoz"). Contents (). Find ("# test" ).css ('color', 'red ');
The effect of this Code is the same as that of direct access to JS. Because of the jquery framework, the code is shorter.
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: Radio"). ATTR ("checked", "true ");
2. in IFRAME, select all radio buttons in the parent window
Vertex (window.parent.doc ument). Find ("input: Radio"). ATTR ("checked", "true ");
If you want to obtain the IFRAME In the IFRAME in the parent window, you can add another frames sub-level. For example:
$ (Window. Frames ["iframe1"]. Frames ["iframe2" ].doc ument). Find ("input: Radio"). ATTR ("checked", "true ");