[英]How to close all opened popups at a time with out their names in javascript
In my application I am redirecting the application to some session_expiry.jsp when session has expired, so in that moment before redirecting to session_expiry.jsp if any popups were opened then I need to close using javascript. 在我的应用程序中,当会话过期时,我会将应用程序重定向到一些session_expiry.jsp,因此在那一刻,如果打开了任何弹出窗口,那么在重定向到session_expiry.jsp之前,我需要使用javascript关闭。 I can't use the popup names because I can't hard code the names for whole application.
我无法使用弹出式名称,因为我无法对整个应用程序的名称进行硬编码。
please help me if you have any idea. 如果您有任何想法请帮助我。
Thanks, Jampanna 谢谢,詹帕纳
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.