Jquery parent window sub-window operations

Source: Internet
Author: User

<1> Js or jQuery visit the framework iframe in the page.
Note: pages in the framework cannot be cross-origin! Assume there are two pages in the same domain.

 

Assume that the parent window index.html has the idSubifrmIframe

 

1. Execute JS in index.html to directly access an element in the subwindow:

 

 document.getElementById('subifrm').contentWindow.document.getElementById('test').style.color='red'  

 

2. Use jquery to access subwindows

 $("#subifrm").contents().find("#test").css('color','red');

 

========================================================== ======================================

========================================================== ======================================

 

<2> Interactive operations are implemented by combining the DOM method with the jquery method.

1. In the parent window, select all radio buttons in IFRAME.

$(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");
2. in IFRAME, select all radio buttons in the parent window
$(window.parent.document).find("input[@type='radio']").attr("checked","true");

========================================================== ======================================

========================================================== ======================================

 

<3> Use jquery to operate iframe

The 1 page contains two ifame

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

 

In leftiframe, jQuery changes the src code of mainiframe:

$("#mainframe",parent.document.body).attr("src","http://www.baidu.com")

 

2. If the content contains an ifame with the ID of mainiframe

<iframe id="mainifame"></ifame>   <iframe id="mainifame"></ifame> 

Ifame contains a someID

<div id="someID">you want to get this content</div>   <div id="someID">you want to get this content</div> 

 

Get someID content

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

 

2. As shown above
Content someID of the mainiframe operated by jQuery in leftiframe

$ ("# Mainframe", parent.doc ument. body ). contents (). find ("someID" ).html (); or $ ("# mainframe", parent.doc ument. body ). contents (). find ("someID "). val ();
Source: http://suan2046.javaeye.com/blog/575421

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.