Last active
January 20, 2020 10:11
-
-
Save gagimilicevic/edf86d9141db0a6c975b984f05d0dbc9 to your computer and use it in GitHub Desktop.
Detect page/tab close jQuery
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
$(window).on("beforeunload", function() { | |
return confirm("Do you really want to close?"); | |
}) | |
let formChanged = false; | |
myForm.addEventListener('change', () => formChanged = true); | |
window.addEventListener('beforeunload', (event) => { | |
if (formChanged) { | |
event.returnValue = 'You have unfinished changes!'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment