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
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<body>
<span id= "Name" ></span>
<input type= "button" "value=" flick Window "onclick=" window.open (' bb.html ') "/>
</body>
Bb.html
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<body>
<input type= "text" id= "Inputvalue"/>
<input type= "button" value= "Add" onclick= "window.opener.document.getElementById (' name '). innerhtml= Inputvalue.value "/>
</body>
Window.opener returns a reference to the window that created the current window, such as clicking a link on the aa.htm and opening the bb.htm, and then we're going to enter a value on the bb.htm and give the aa.htm an ID of "name" TextBox, you can
is written as:
window.opener.document.getElementById ("name"). Value = "entered data";
Window.opener.document.getElementById ("name"). Innerhtml= "entered data";