Gets the elements in the IFRAME in the parent window
IE under:
Format: window.frames["The name value of the IFRAME"].document.getelementbyid ("ID of the control in the IFrame"). Click (); Example: window.frames[
Methods that are supported:
Format: document.getElementById ("id value of iframe"). ContentWindow.document.getElementsByName (' radios ');//ie Firefox support
gets the element of the parent window in the IFRAME
JS Code
Format: Window.parent.document.getElementById (the element ID of the parent window). Click (); Example: Window.parent.document.getElementById ("Btnok"). Click ();
Jquery
Gets the elements in the IFRAME in the parent window
Format: $ ("#iframe的ID"). Contents (). Find ("#iframe中的控件ID"). Click (); // jquery Method 1 Instance: $ ("#ifm"). Contents (). Find ("#btnOk"). Click (); // jquery Method 1 Format: $ ("#iframe中的控件ID", Document.frames ("frame name"). Document). Click (); // jquery Method 2 Instance: $ ("#btnOk", Document.frames ("IFM"). Document). Click (); // jquery Method 2
Gets the element of the parent window in the IFRAME
Format: $ (' #父窗口中的元素ID ', parent.document). Click (); Instance: $ (
If the page cross-domain, the above method will not work!
Instance code: index.html
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><P>Current frame</P><iframesrc= "if.html"width= "+"Height= "+"ID= "Currentif"name= "Currentif"></iframe></Body></HTML><Scriptlanguage= "JavaScript">window.onload= function(){ varSD=Window.top.document.getElementById ("currentif"). Contentwindow;
You can also get rid of the front window.top here.varson=Sd.document.getElementById ("Linkif"); Son.onclick= function() {alert ("1"); };}
Be sure to put it under the onload. If you write directly, it can cause the element to get failed! </Script>
Instance code: if.html
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><PID= "Linkif">Embedded frame</P></Body></HTML>
How to get the contents of the IFRAME frame through JS