Showing A Jquery Popup Before Browser Window Closes
I'm using the following js to show a popup before the browser/window closes. But it does not seem to be working. $(window).bind('beforeunload', function(e) { $('#beforeclo
Solution 1:
You cannot safely do that.
onbeforeunload
is designed in a way to avoid completely preventing the user from leaving your page. The only thing you should do is return a string with a message why the user might not want to leave the page. This message is displayed to the user unless he's using firefox.
Solution 2:
Try this:
<scripttype="text/javascript">
$(function() {
functionconfirmmsg() {
return"Mail Not sent";
}
window.onbeforeunload = confirmmsg;
});
</script>
Solution 3:
Try changing it to
$(window).bind('beforeunload', function(e) {
$('#beforeclose').click();
e.preventDefault();
returnfalse; // just in case..
});
from jQuery documentation:
event.preventDefault()
Description: If this method is called, the default action of the event will not be triggered.
Basically, you are binding the function that shows the popup on the beforeunload
event, but that does not block the browser like an alert window or something like that. Using event.preventDefault()
you will stop the execution of event flow.
Post a Comment for "Showing A Jquery Popup Before Browser Window Closes"