Skip to content

Instantly share code, notes, and snippets.

@marcialsoto
Created January 9, 2019 22:04
Show Gist options
  • Select an option

  • Save marcialsoto/08ee9ad61b953e367ce2af99d45004b9 to your computer and use it in GitHub Desktop.

Select an option

Save marcialsoto/08ee9ad61b953e367ce2af99d45004b9 to your computer and use it in GitHub Desktop.
Use of onbeforeunload for prevent closing page
<script>
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 () {
$(".safe").click(function () {
window.onbeforeunload = null;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment