我想只在浏览关闭时销毁会话。 我正在使用window.onbeforeunload函数,但它在下面的情况下触发:
我只想为第6个案例做一些事情(Make ajax call。)
对于案例1,2,3,我的代码工作正常但我需要为案例4& 5。
我的代码下面:
var isOK = true;
$(document).bind('keydown', function(e) {
if (e.keyCode == 116){
isOK = false;
}
if (e.keyCode == 82 && e.ctrlKey) {
isOK = false;
}
if (e.keyCode == 82 && e.shiftKey && e.ctrlKey) {
isOK = false;
}
});
window.onbeforeunload = function(event) {
if(isOK)
{
$.ajax({
url: "server.jsp",
type: "POST",
data: "KillSession"
});
alert("Your session is expired!!!");
}else{
alert("onbeforeunload call!!! but ajax not call");
}
};