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,