What's the difference between window.parent and Window.opener?

Source: Internet
Author: User

  The following code is about the difference between window.parent and Window.opener, We use WINDOW.OPENER.DOCUMENT.GETELEMENTBYID (name) if we want to pass the value of an IFRAME to another frame. Value = Uvalue; this form.

Window.parent can get a frame's parent window or parent frame. The parent of the top-level window refers to itself.

You can use this feature to determine whether the window is a top-level window. Such as:


function Istopwindow (Win)


if (win.parent = win) return true;

else return false;


Window.opener refers to the parent page of the window.open open page.

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. Like what:

In A.html, window.open a new window b.html by clicking on a button. 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.

Window.opener returns a reference to the window that created the current window, such as clicking a link on the a.htm and opening the b.htm, and then we're going to enter a value on the b.htm and give it a TextBox with ID "name" on the a.htm. It can be written as:

Window.opener.document.getElementById ("name"). Value = "entered data";

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.