My previous post is window.onbeforeunload and window.onunload is not working in Firefox, Safari, Opera? and it not worked in this situation. So I created a new thread.
Now this works in IE
, safari
, and chrome
.
only beforeunload
event fired in firefox
and unload
not fired.
Both not working in Opera
.
My jQuery will be:
$(window).on('beforeunload', function () {
return 'Are you sure want to LOGOUT the session ?';
});
$(window).unload(function () {
closeWindow();
});
function closeWindow() {
alert('fdf');
$.ajax({
type: 'post',
url: 'Test.jsp',
async: false,
//data : "userId="+encodeURIComponent(userId)+"&secureKey="+encodeURIComponent(secureKey)+"&nickname="+encodeURIComponent(name)+"&sid="+Math.random() ,
cache: false,
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
scriptCharset: 'utf-8',
dataType: 'html',
//alert(sessionId+" "+userId+ " "+secureKey+" "+message);
error: function (xhr, ajaxOptions, thrownError) {
//alert("status :"+xhr.status+"\nthrownError : "+thrownError+"\nresponseText : "+xhr.responseText);
},
success: function (responseData, status) {
//alert("LogoutAction Response Data : "+ responseData +"\nStatus : "+status);
var checkMsg = $.trim(responseData);
if (checkMsg != 'null' && checkMsg.length != 0 && checkMsg != null) {
alert('Window close : ' + checkMsg);
}
},
});
}
My Test.jsp
will be ,
<% System.out.println("Window is closed !");
out.println("Window is closed !"); %>