JQuery controls iFrame (instance code)

Source: Internet
Author: User

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:

<Iframe src00000000test.html "id =" iframe1 "width =" 700 "height =" 300 "frameborder =" 0 "scrolling =" auto "> </iframe>

IE7 passed the test

Code:
Copy codeThe Code is as follows:
<! 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>
<Title> jQuery controls iframe </title>
<Script type = "text/ecmascript" src = "../js/jquery-1.2.6.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# T1"). hover (function () {alert ('');});
// $ ("Iframe"). contents (). find ("body"). append ("I'm in an iframe! ");
// $ (Window. frames ["iframe1" 2.16.doc ument ). find ("input [@ type = 'text']"). attr ("size", "30px ");
// $ ("# Iframe1"). contents (). find ("# d1" ).css ('color', 'red ');
// $ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ name = 't1']" cmd.css ({background: "#369 "});
// $ ("# Iframe1"). src ("test.html ");
});
</Script>
</Head>
<Body>
<Div>
<Input type = "text" id = "t1"/>
<Iframe id = "iframe1" src = "child.htm"> </iframe>
<Iframe src = "child.htm" width = "300" height = "100"> </iframe>
</Div>
<Div>
</Div>
</Body>
</Html>

Use jquery to operate iframe

1. The content contains two ifame

<Iframe id = "leftiframe"... </iframe>
<Iframe id = "mainiframe... </iframe>

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
<Iframe id = "mainifame"...> </ifame>
Ifame contains a someID
<Div id = "someID"> you want to get this content </div>
Get someID content

$ ("# Mainiframe "). contents (). find ("someID" ).html () html or $ ("# mainiframe "). contains (). find ("someID "). text () Value

3. In the parent window, select all radio buttons in IFRAME.
$ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");

Then the find method is still used to select the id.
$ (Window. frames ["iframe1" cmd.doc ument). find ("# id ")

Related Article

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.