Window. open subwindow, close all subwindows, window. open window

Source: Internet
Author: User

Window. open subwindow, close all subwindows, window. open window

Requirement: The subwindow is opened through the window. open method. When the main window is closed, the subwindow should also be closed.
Implementation ideas:
1. The second parameter winName of window. open (url, winName) in the subwindow function can uniquely identify the window to be opened. Therefore, you only need to use the winName. close () function to close the subwindow.
2. A page may have multiple subwindows. Therefore, an array is required to store all the Child Window objects. When the function is disabled, You can traverse the array.
3. You can open the subwindow again. Infinite Loop. Therefore, you need to determine.
This requirement can be implemented in two ways.

  • Call the close function of the subwindow.
    This method is easy to understand, but the browser Close event is not found in the actual implementation process. You need to click the button to close or the shortcut key to close it, which is a little troublesome,

  • Recursively close subwindow
    This method is easy to implement. The disadvantage is that the object arrays of all window storage subwindows must have the same names.

The following describes how to recursively close subwindows and subwindows.

Function closeSonWindow (win) {for (var index = 0; index <win. length; index ++) {// if the window is closed if (win [index]. closed) {continue;} // if the window does not have any subwindow that can be opened, if (typeof (win [index]. openedWindow) = "undefined") {win [index]. close (); continue;} if (win [index]. openedWindow. length = 0) {win [index]. close ();} else {closeSonWindow (win [index]. openedWindow); win [index]. close ();}}}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.