I have question related to Browser close event..
How to capture the Browser close event without refresh event.
Thanks in Advance.
I have question related to Browser close event..
How to capture the Browser close event without refresh event.
Thanks in Advance.
Using window.onbeforeunload
but this will also be triggered when you reload the browser or moving to a different page by clicking on a link.
window.onbeforeunload = function(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
};
Note: window.onbeforeunload
will not work on touch devices except Android.
Try this one
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(function () {
$("a").not('#LogOut').click(function () {
window.onbeforeunload = null;
});
$(".btn").click(function () {
window.onbeforeunload = null;
});
});