在我的應用程序中,當會話過期時,我將應用程序重定向到某個session_expiry.jsp,因此在重定向到session_expiry.jsp之前,如果有彈出窗口打開然後我需要關閉使用JavaScript。我無法使用彈出式名稱,因爲我無法硬編碼整個應用程序的名稱。如何在javascript中一次關閉所有打開的彈出窗口
請幫助我,如果你有任何想法。
感謝, Jampanna
在我的應用程序中,當會話過期時,我將應用程序重定向到某個session_expiry.jsp,因此在重定向到session_expiry.jsp之前,如果有彈出窗口打開然後我需要關閉使用JavaScript。我無法使用彈出式名稱,因爲我無法硬編碼整個應用程序的名稱。如何在javascript中一次關閉所有打開的彈出窗口
請幫助我,如果你有任何想法。
感謝, 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>
你有沒有? –
[關閉所有彈出窗口(可能重複http://stackoverflow.com/questions/17756376/close-all-pop-up-windows ) –
複製[獲取打開的彈出窗口列表](http://stackoverflow.com/questions/9212537/get-list-of-opened-popup-windows) – jfriend00