Skip to content

Instantly share code, notes, and snippets.

@woss
Last active February 1, 2021 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save woss/3c2296d9e67e9b91292d to your computer and use it in GitHub Desktop.
Save woss/3c2296d9e67e9b91292d to your computer and use it in GitHub Desktop.
2 methods for binding and unbinding window.onbeforeunload event
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