Javascript calls the parent/child form Method

Source: Internet
Author: User

In actual programming, sometimes we need to access the child form in the parent form or access and operate on the child form, or we can access or call the method of the parent form in the child form. The implementation is very simple. See the following example:

 

"Id =" code_closed_image_105656 "style =" display: none; ">" id = "code_open_image_105656"> code
Parent form (webform1.aspx ):

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> parent form </title>
<SCRIPT type = "text/JavaScript">
VaR sys = function (){};
SYS. sayhello = function (){
Alert ('Hello parent/opner page !! ');
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<IFRAME id = "IFM"> </iframe>
<Input type = "button" onclick = "document. getelementbyid ('ifm '). src = 'webform2. aspx '; // window. open ('webform2. aspx ') "value =" open child "/>
<Input type = "button" onclick = "window. Frames ['ifm']. SYS. sayhello ()" value = "INVOKE child domain"/>
</Form>
</Body>
</Html>

Child form (webform2.aspx ):

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> subform </title>
<SCRIPT type = "text/JavaScript">
VaR sys = function (){};
SYS. sayhello = function (){
Alert ('Hello child page !! ');
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Input type = "button" value = "INVOKE parent/opner domain" onclick = "window. Parent. SYS. sayhello ();"/>
</Form>
</Body>
</Html>

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.