JS parent page and child page pass value method to each other

  • 2020-03-30 02:17:17
  • OfStack

A child page is a parent page that pops up through window.open
To pass values to the parent page, just add window.opener before the document.
Such as:
1. Parent page code:

< HTML XMLNS = "http://www.w3.org/1999/xhtml" >
< Head>
< Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = utf-8 "/ >
< Title> No title document title>
Head>
< Script language = "javascript" >
The function tanchu ()
{
      Window. The open (" Untitled - 5. HTML ");    
}
Script>
< Body>
      < Form id="form1" name="form1" method="post" action="";
              < Label> < Input type="submit" name="button" id="button" value=" submit"
                      "Onclick =" tanchu () / >
              Label> < Label> < Input type="text" name="textfield" id="textfield" />
              Label>
      Form>
< / body>
< / html>
2. Subpage code:

< HTML XMLNS = "http://www.w3.org/1999/xhtml" >
< Head>
< Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = utf-8 "/ >
< Title> No title document title>
Head>
< Script language = "javascript" >
The function aaa ()
{
      Window. Opener. Document. GetElementByIdx (' textfield). Value = '123123123';
}
Script>
< Body>
      < Form id="form1" name="form1" method="post" action="";
              < Label> < Input type="submit" name="button" id="button" value=" submit"
                      "Onclick =" aaa () / >
              Label>
      Form>
< / body>
< / html>
Child pages are pages in the iframe

To pass a value from a child page to the parent page, simply append parent to the document.
1. Parent page code:

< HTML XMLNS = "http://www.w3.org/1999/xhtml" >
< Head>
< Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = utf-8 "/ >
< Title> No title document title>
Head>
< Body>
      < Form id="form1" name="form1" method="post" action="";
              < Label> < Input type="text" name="textfield" id="textfield" />
              Label>
              < Myiframe iframe id = "" SRC =" Untitled - 3. HTML >" Iframe>
      Form>
< / body>
< / html>
2. Subpage code

< HTML XMLNS = "http://www.w3.org/1999/xhtml" >
< Head>
< Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = utf-8 "/ >
< Title> No title document title>
Head>
< Script language = "javascript" >
The function (aa)
{
      Var a = parent. Document. GetElementByIdx (' textfield). The value;
      Alert (a);
}
Script>
< Body>
      < Form id="form1" name="form1" method="post" action="";
              < Label> < Input type="submit" name="button" id="button" value=" submit"
                      "OnClick =" aa () / >
              Label>
      Form>
< / body>
< / html>


Related articles: