I want to destroy session only when browse is close. I am using window.onbeforeunload function but it fired on below cases:
- page redirection by link navigation,form submission or window.location function
- F5 or CTRL+F5 press
- CTRL+R, CTRL+SHIFT+R press
- When click on reload button of the browser
- focus on URL typing box and press enter
- When close the browser
I want to do somthing(Make ajax call) only for 6th case.
For case 1,2,3 my code working properly but what i need to do for case 4 & 5.
My code Below:
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");
}
};