Opener and parent in javascript

Source: Internet
Author: User

I recently reviewed JavaScript and found that some concepts about the frame framework and window are a bit confusing. I will record them here.

Opener

To create a child window in the current window, you may need to reference the parent window from the Child window, so there is an opener.

Opener is who opens my project. For example, A page uses window. when the open dialog box appears, the window where page A is located is the opener of page B. You can access page A through the opener object on page B.

Parent

The current window contains the frame framework. In a framework set, parent is required to access the child framework when accessing the parent framework.

Parent indicates the parent window. For example, if A page A uses iframe or frame to call page B, the window where page A is located is the parent of page B.


In conclusion, opener is responsible for the parent-child relationship between windows, and parent is responsible for the parent-child relationship between frameworks.


Instance

 Test Parent And Opener<script type="text/javascript">var newWindow = window.open("http://www.w3school.com.cn",'','width=400,height=200');window.onload = function(){alert("newWindow.opener: "+newWindow.opener.document.title);alert("newWindow.parent.document: "+newWindow.parent.document);alert("window.frame[0].parent:"+window.frames[0].parent.document.title);alert("window.frame[0].opener:"+window.frames[0].opener);}</script><frameset rows="50%,50%"><frame src="http://www.w3school.com.cn"><frameset cols="25%,75%"><frame src="http://www.w3school.com.cn"><frame src="http://www.w3school.com.cn"></frameset></frameset>

The result is:

1,

2,

3,

4,


Related Article

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.