How to identify browser tab closing using javascript or jquery? I have to give a confirmation message when user click on the browser close button. If user press yes button I have to load another page on the same tab. if press cancel. then close the tab. any body knows the scripts for this functionality. Please help me :(
+1
A:
Try something like this:
$(window).unload(function() {
var bye = confirm("Go away?");
if (bye) {
// do stuff
window.location = "http://somewhere_else";
} else {
// do stuff?
// stay here
}
});
Ken Redler
2010-07-16 04:24:16
+1
A:
onbeforeunload = function() {
return 'string';
}
would give a prompt. you can also insert a modal through:
onbeforeunload = function() {
var x = window.open('file.html');
}
you can't really customize it per how you want it, it's locked down by the browser.
meder
2010-07-16 04:24:26
+1
A:
This site uses onbeforeunload
. You can play around with it and see if it does what you need. Type in some text into the answer box and try to refresh, navigate away, close tab, close browser.
Igor Zevaka
2010-07-16 04:27:57