我在登录完成之后用window.open()打开一个新窗口(登录之后的主页面),代码:
window.open("login!main.action","main","height="+height+", width="+width+", toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
请问如何用js捕捉到新打开的窗口的关闭事件?我想在关闭窗口的时候将服务器端session信息清除。
我写了一段,好像不执行,但是在正常窗口里这段是可以执行的。代码:
window.onbeforeunload = function() {
var n = window.event.screenX - window.screenLeft; 
var b = n > document.documentElement.scrollWidth-20; 
if(b && window.event.clientY < 0 || window.event.altKey) { //是关闭而非刷新
$.get("<%=basePath%>/sys/login!cleanSession.action");
alert("是关闭而非刷新");
} esle{
alert("是刷新而非关闭");
}
}