<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