Created
January 9, 2019 22:04
-
-
Save marcialsoto/08ee9ad61b953e367ce2af99d45004b9 to your computer and use it in GitHub Desktop.
Use of onbeforeunload for prevent closing page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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