Last active
February 1, 2021 15:58
-
-
Save woss/3c2296d9e67e9b91292d to your computer and use it in GitHub Desktop.
2 methods for binding and unbinding window.onbeforeunload event
This file contains 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
var windowReloadBind = function(message) { | |
window.onbeforeunload = function(event) { | |
if (message.length === 0) { | |
message = ''; | |
} | |
if (typeof event == 'undefined') { | |
event = window.event; | |
} | |
if (event) { | |
event.returnValue = message; | |
} | |
return message; | |
} | |
}; | |
var windowReloadUnBind = function() { | |
window.onbeforeunload = function() { | |
return null; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment