JavaScript child windows methods for calling parent window variables and functions

Source: Internet
Author: User

The purpose of local refresh is to make a parent window open a child window and invoke the parent window when the child window is Closed.

Parent Window:

1 <!DOCTYPE HTML Public "-//w3c//dtd XHTML 1.0 transitional//en"2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3 <HTMLxmlns= "http://www.w3.org/1999/xhtml">4 <Head>5   <title>Parent</title>6   <Scripttype= "text/javascript">7     varParentpara='Parent';8     functionparentfunction () {9 Alert (parentpara);Ten     } one   </Script> a </Head> - <Body> -   <Buttononclick= "parentfunction ()">Show variable values</Button> the   <Buttononclick= "window.open (' child.html ')">Open a new window</Button> - </Body> - </HTML>

Child Window:

1 <!DOCTYPE HTML Public "-//w3c//dtd XHTML 1.0 transitional//en"2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3 <HTMLxmlns= "http://www.w3.org/1999/xhtml">4 <Head>5   <title>Child</title>6   <Scripttype= "text/javascript">7     functionModify () {8 Opener.parentpara=' child';9     }Ten   </Script> one </Head> a <Body> -   <Buttononclick= "opener.parentfunction ()">Methods to invoke the parent page</Button> -   <Buttononclick= "modify ()">Change the value of a variable in the parent page</Button>  the </Body> - </HTML>

A child page is an IFRAME of the parent page

Parent Page:

1 <!DOCTYPE HTML Public "-//w3c//dtd XHTML 1.0 transitional//en"2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3 <HTMLxmlns= "http://www.w3.org/1999/xhtml">4 <Head>5   <title>Parent</title>6   <Scripttype= "text/javascript">7     functionFill () {8       //Alert (frame1.window.childPara); Displays the value of the variable within the frame19       varStr=document.getElementById ('txt1'). value; //get the value entered in the text boxTen Frame1.window.div1.innerHTML=str;//fill in a div with the values in the sub-page one     } a   </Script> - </Head> - <Body> the   <Divstyle= "background-color:yellow;width:300px;height:300px;"> - Parent Page -     <iframeID= "frame1"src= "child.html"frameborder= "0"scrolling= "no"width= "120px"Height= "120px"></iframe> -     <BR/><BR/><BR/><BR/> +     <inputID= "txt1"type= "text"/> -     <Buttononclick= "fill ()">Populate a text box with values in a sub-interface</Button> +   </Div> a </Body> at </HTML>

Sub-page:

1 <!DOCTYPE HTML Public "-//w3c//dtd XHTML 1.0 transitional//en"2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3 <HTMLxmlns= "http://www.w3.org/1999/xhtml">4 <Head>5   <title>Child</title>6   <Scripttype= "text/javascript">7     functionfun () {8 Parent.fill ();9     }Ten   </Script> one </Head> a <Body> -   <Divstyle= "background-color:lightblue;width:100px;height:100px;"> -     <b>Sub-page</b><BR/> the     <ahref="#"onclick= "fun ()">The half page button</a> -     <DivID= "div1"style= "color:red;"> -     </Div> -   </Div> + </Body> - </HTML>

When the parent page is refreshed, the IFRAME is refreshed with it, and the parent page is not refreshed when the IFRAME is Refreshed.

In addition, if one module in Angularjs calls the method of another module: the main idea is to get the angular and document of the other module, and then use the Angular.element (document.getelementbyid ("aaa" ));

where: var angular = Window.opener.angular;var Document = window.opener.document, Depending on the actual situation in the Acquisition.

JavaScript child windows methods for calling parent window variables and functions

Related Article

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.