如何在javascript中一次关闭所有打开的弹出窗口而不显示其名称

如何在javascript中一次关闭所有打开的弹出窗口而不显示其名称,javascript,Javascript,在我的应用程序中,当会话过期时,我将应用程序重定向到某个session_expiry.jsp,因此在重定向到session_expiry.jsp之前,如果打开了任何弹出窗口,那么我需要使用javascript关闭。我不能使用弹出名称,因为我不能硬编码整个应用程序的名称 如果你有任何想法,请帮助我 谢谢, 贾姆潘纳 var窗口=[]; 函数conf(){ var rand_no_c=Math.random(); var con=rand_no_c.toString(); var_win='chil

在我的应用程序中,当会话过期时,我将应用程序重定向到某个session_expiry.jsp,因此在重定向到session_expiry.jsp之前,如果打开了任何弹出窗口,那么我需要使用javascript关闭。我不能使用弹出名称,因为我不能硬编码整个应用程序的名称

如果你有任何想法,请帮助我

谢谢, 贾姆潘纳


var窗口=[];
函数conf(){
var rand_no_c=Math.random();
var con=rand_no_c.toString();
var_win='child'+con.子字符串(2);
windows[var_-win]=window.open('child.aspx',var_-win,'width=1100,height=700,left=50,top=20,status=0');
}
函数closewindow(){
用于(windows中的w){
如果(!windows[w]。已关闭){
windows[w]。关闭();
}
}
}
*{边距:0;填充:0;}
打开子窗口
关闭所有窗口

可能重复的重复感谢您的回复,实际上我不想硬编码任何名称,这里我要在“instanceName”中提到的是弹出名称还是其他名称,请澄清我的疑问您不必传递弹出名称。。它是用来打开和关闭的。。但是你只需要关闭所有的函数就可以了。和closeall功能不需要弹出名称。它不工作!!我正在获取WindowDialog变量的null或不是对象。我使用了以下代码:var WindowDialog=new function(){this.openedWindows={};this.closeAll=function(){for(this.openedWindows中的var dialog)this.openedWindows[dialog].close();};};WindowDialog.closeAll();对吗?通过这段代码,我在WindowDialog中得到null或不是一个对象脚本错误,您能发送使用这段代码关闭所有pop的正确方法吗?告诉我您是如何打开pop的?
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();
};
};


// close all dialogs

WindowDialog.closeAll();
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">

var windows = [];
function conf() {
    var rand_no_c = Math.random();
    var con = rand_no_c.toString();
    var_win = 'child'+con.substring(2);
    windows[var_win] = window.open('child.aspx',var_win,'width=1100,height=700,left=50,top=20,status=0');
}

function closewindow() {
for(w in windows) {
    if(!windows[w].closed) {
        windows[w].close();
        }
    }
}
</script>

<style type="text/css">
    * {margin:0;padding:0;}
</style>

</head>
<body>
<div>
    <button type="button" onclick="conf();">open child window</button>
    <button type="button" onclick="closewindow();">close all windows</button>
</div>

</body>
</html>