Close all pop-up windows [duplicate]

大憨熊 提交于 2019-12-03 09:13:49

You can make a new function that basically wraps the existing functionality with what you're trying to do.

var WindowDialog = new function() {
    this.openedWindows = {};

    this.open = function(instanceName) {
        var handle = window.open(Array.prototype.splice.call(arguments, 1));

        this.openedWindows[instanceName] = handle;

        return handle;
    };

    this.close = function(instanceName) {
        if(this.openedWindows[instanceName])
            this.openedWindows[instanceName].close();
    };

    this.closeAll = function() {
        for(var dialog in this.openedWindows)
            this.openedWindows[dialog].close();
    };
};

Sample Usage

WindowDialog.open('windowName', /* arguments you would call in window.open() */);
WindowDialog.open('anotherName', /* ... */);
WindowDialog.open('uniqueWindow', /* ... */);
WindowDialog.open('testingAgain', /* ... */);
WindowDialog.open('finalWindow', /* ... */);

// closes the instance you created with the name 'testingAgain'
WindowDialog.close('testingAgain');

// close all dialogs
WindowDialog.closeAll();

try this to open and close

document.MyActiveWindows= new Array;

function openWindow(sUrl,sName,sProps){
document.MyActiveWindows.push(window.open(sUrl,sName,sProps))
}

function closeAllWindows(){
for(var i = 0;i < document.MyActiveWindows.length; i++)
document.MyActiveWindows[i].close()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!