JavaScript invoke IFRAME parent window and child window element example summary

Source: Internet
Author: User

1. jquery Gets the parent page element code in the IFRAME page as follows:

$ ("#objid", parent.document)

2. jquery gets the element of an IFRAME child page on the parent page

The code is as follows:

$ ("#objid", Document.frames (' Iframename '). Document)

3.js Gets the parent page element code in the IFRAME subpage as follows:

Indow.parent.document.getElementByIdx_x ("Element id");

4.js gets the IFRAME child page element code on the parent page as follows:

window.frames["iframe_id"].document.getelementbyidx_x ("element ID");

5. The parent class function is called within the subclass IFRAME:

Window.parent.func ();

Add

Js
Get 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 the 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
Get 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 ("Name of Frame"). 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 ();

Example

A complete example
Test.htm <HTML>
<HEBD>
<TITLE> Test Page </TITLE>
<script src= "Prototype-1.4.0.js" ></script>
<script language= "JavaScript" >
Function Show ()
{
window.frames["Iframe_text"].document.getelementby Id ("myH1"). InnerHTML = "http://hi.wonsoft.cn";
}
</script>
</HEBD>
<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=" Getbttributemethod "></textarea>
<input type= "button" ondlick= "Show ();" value= "Submit"/>
</form>
&LT;H1 id= "MyH1" >d</BODY> </HTML>
Frame_test.htm <! Dodtype html Publid "-//W3D//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition al.dtd ">
<meta http-equiv= "Dontent-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<script language= "JavaScript" >
Function Show ()
{
Parent.document.getElementById ("MyH1"). InnerHTML = http://zfrong2000.cn;
}
</script> <body>
&LT;H1 id= "MyH1" >ha<form action= "" method= "POST" >
<input name= "abc" id= "abc" type= "Text" maxlength= "a" value= "abc"/>
<br/>
<textarea cols= "rows=" id= "text" ></textarea>
<br/>
<input type= "button" value= "submitted" onclick= "Show ();" />
</form>
</body> Test.htm inside Firefox access IFrame must use name, cannot use ID, so to name= "Iframe_test".

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.