Home > Web Front-end > JS Tutorial > Detailed analysis of the difference between opener and parent in js_javascript skills

Detailed analysis of the difference between opener and parent in js_javascript skills

WBOY
Release: 2016-05-16 17:04:03
Original
1207 people have browsed it

The opener is who opens mine. For example, page A uses window.open to pop up the window of page B, then the window where page A is located is the opener of page B. Page A can be accessed through the opener object on page B.

Parent represents the parent window. For example, if page A uses iframe or frame to call page B, then the window where page A is located is the parent of page B. In JS, window.opener is just a reference to the pop-up window's parent window. For example: in a.html, window.open opens a new window b.html by clicking a button. Then in b.html, you can reference a.html through window.opener (omitted and written as opener), including the document and other objects of a.html, and operate the content of a.html.

If this reference fails, null will be returned. Therefore, before calling the opener object, you must first determine whether the object is null, otherwise a JS error of "the object is empty or does not exist" will occur.

Example:
aa.html

Copy code The code is as follows:




Untitled Document






bb.html
Copy code The code is as follows:





Untitled Document






window.opener returns a reference to the window that created the current window , for example, clicked a link on aa.htm and opened bb.htm, and then we plan to enter a value on bb.htm and assign it to a textbox with the id "name" on aa.htm, then

is written as:
window.opener.document.getElementById("name").value = "Input data";
window.opener.document.getElementById( "name").innerHTML= "Input data";

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template