A detailed analysis of the difference between opener and parent in JS

Source: Internet
Author: User
Tags xmlns

  This article is mainly to JS opener and the difference between the parent of a detailed introduction, the need for friends can come to the reference, I hope to help you.

Opener that who opened my, such as a page using window.open pop-up b page window, then a page is the window is the B page opener, the B page through the opener object can access a page.   Parent represents the parents window, such as a page with an IFRAME or frame to invoke B page, then page A is the parent of page B. In JS, Window.opener is just a reference to the pop-up window's parent window. For example: a.html, by clicking the button and so on to window.open out a new window b.html. Then in b.html, we can use Window.opener (omit write as opener) to reference a.html, including a.html document and other objects, manipulate a.html content.   If this reference fails, then NULL is returned. Therefore, before calling the opener object, you must first determine whether the object is null, otherwise the "object is empty or does not exist" JS error.   Example: aa.html   code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> <title> Untitled document </title> </head> <body> <span id=" name "></span> <input type= "button" "value=" Window "onclick=" window.open (' bb.html ') "/> </body> </html   bb.html code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/dtd/xhtml1-transitional.dtd ">  <html xmlns=" http://www.w3.org/1999/xhtml ">  <head >  <meta http-equiv= "content-type" content= "text/html; Charset=utf-8 "/>  <title> Untitled document </title>  </head>  <body>  <input Type= "text"  id= "Inputvalue"/>  <input type= "button"  value= "Add" onclick= " Window.opener.document.getElementById (' name '). Innerhtml=inputvalue.value "/>  </body>  </ html>    Window.opener Returns a reference to the window that created the current window. For example, click on a link on the aa.htm to open the bb.htm, and then we intend to enter a value on the bb.htm and then give Aa.htm a textbox with the ID "name", you can   write as: Window.opener.document.getElementById ("name"). Value = "entered data"; Window.opener.document.getElementById ("name"). Innerhtml= "entered data";  

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.