Gets the elements in the IFRAME in the parent window
1.
Format: window.frames["The name value of the IFRAME"].document.getelementbyidx_x ("ID of the control in the IFrame"). Click ();
Example: window.frames["IFM"].document.getelementbyidx_x ("Btnok"). Click ();
2.
Format:
var obj=document.getelementbyidx_x ("Name of IFrame"). Contentwindow;
var ifmobj=obj.document.getelementbyidx_x ("ID of the control in the IFrame");
Ifmobj.click ();
Instance:
var obj=document.getelementbyidx_x ("IFM"). Contentwindow;
var ifmobj=obj.document.getelementbyidx_x ("Btnok");
Ifmobj.click ();
Gets the element of the parent window in the IFRAME
Format: window.parent.document.getElementByIdx_x (the element ID of the parent window). Click ();
Example: window.parent.document.getElementByIdx_x ("Btnok"). Click ();
Jquery
Gets the elements in the IFRAME in the parent window
1.
Format: $ ("#iframe的ID"). Contents (). Find ("#iframe中的控件ID"). Click ();//jquery Method 1
Instance: $ ("#ifm"). Contents (). Find ("#btnOk"). Click ();//jquery Method 1
2.
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 ();
Example: $ (' #btnOk ', parent.document). Click ();
Parent window Gets the JS method in the iframe of the child window
One, the parent window calls the IFrame child window method
1. HTML syntax: <iframe name= "MyFrame" src= "child.html" ></iframe>
2. parent window Call Child window: MyFrame.window.functionName ();
3, sub-window products call the parent window: Parent.functionname ();
In short, it is the addition of a parent to a variable or function that is called in a child window. That's it.
4, parent window page Source:
Copy the code code as follows:
<script type= "Text/javascript" >
function say () {
Alert ("parent.html------>i ' m at Parent.html");
}
function Callchild ()
{
Document.frames ("MyFrame"). F1 ();
MyFrame.window.say ();
}
</script>
<body>
<input Type=button value= "invoke functions in Child.html say ()" onclick= "Callchild ()" >
<iframe name= "MyFrame" src= "child.html" ></iframe>
</body>
5. Sub-window page:
Copy the code code as follows:
<script type= "Text/javascript" >
function Say ()
{
Alert ("Child.html--->i ' m at Child.html");
}
function Callparent () {
Parent.say ();
}
</script>
<body>
<input Type=button value= "call Say () function in parent.html" onclick= "Callparent ()" >
</body>
Second, the IFRAME parent window and the child window Mutual Call method
1, the use of IE method:
Parent window calling child window: Iframe_ID.iframe_document_object.object_attribute = Attribute_value
Example: onclick= "iframe_text.myh1.innertext= ' http://www.pint.com ';"
child window called parent window: Parent.parent_document_object.object_attribute = Attribute_value
Example: onclick= "parent.myh1.innertext= ' http://www.pint.com ';"
2. How to use Firefox:
There is no problem with IE, but it is not normal under Firefox. In Firefox, it should be called the following method:
The parent window calls the child window: window.frames["iframe_id"].document.getelementbyid ("Iframe_document_object"). Object_attribute = Attribute_value
Example: window.frames["Iframe_text"].document.getelementbyid ("MyH1"). innerhtml= "Http://hi.jb51.net";
The child window calls the parent window: parent.document.getElementById ("Parent_document_object"). Object_attribute = Attribute_value
Example: Parent.document.getElementById ("myH1"). InnerHTML = "Http://jb51.net";
3, The complete example
Test.htm
Copy the code code as follows:
<HTML>
<HEAD>
<TITLE> Test Page </TITLE>
<script src= "Prototype-1.4.0.js" ></script>
<script language= "JavaScript" >
Function Show ()
{
window.frames["Iframe_text"].document.getelementbyid ("MyH1"). InnerHTML = "Http://hi.jb51.net";
}
</script>
</HEAD>
<BODY>
<iframe height= "width=" src= "iframe_test.htm" name= "Iframe_text" ></iframe>
<form action= "" method= "POST" >
<input name= "haha" id= "haha" type= "text" maxlength= "+" value= "haha"/>
<br/>
<textarea cols= "rows=" 5 "id=" Getattributemethod "></textarea>
<input type= "button" onclick= "Show ();" value= "Commit"/>
</form>
<H1 id= "MyH1" >d
</BODY>
</HTML>
Frame_test.htm
Copy the code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<script language= "JavaScript" >
Function Show ()
{
Parent.document.getElementById ("MyH1"). InnerHTML = Http://jb51.net;
}
</script>
<body>
<H1 id= "MyH1" >ha
<form action= "" method= "POST" >
<input name= "abc" id= "abc" type= "Text" maxlength= "+" value= "abc"/>
<br/>
<textarea cols= "rows=" id= "text" ></textarea>
<br/>
<input type= "button" value= "Submit" onclick= "Show ();" />
</form>
</body>
Test.htm inside Firefox access IFrame must use name, cannot use ID, so change to Name= "Iframe_test".
Third, how to dynamically change the SRC value of the IFRAME in C #, dynamically pointing to a Web page
1) If it's a JavaScript script
Add an ID to the IFRAME such as <iframe id=frmlist ...
In script write
Frmlist.document.location=strnewurl
2) If it is a background program
Add an ID to the IFRAME, plus runat=server such as <iframe id=frmlist runat=server ...
Write in the program.
FRMLIST.ATTRIBUTES.ADD ("src", strnewurl);
Parent window and IFRAME access to each other