Skip to content

Instantly share code, notes, and snippets.

@Kukks
Created April 21, 2016 09:43
Show Gist options
  • Save Kukks/503e61b705a9d29192d1822d1e451c9f to your computer and use it in GitHub Desktop.
Save Kukks/503e61b705a9d29192d1822d1e451c9f to your computer and use it in GitHub Desktop.
Wrapped the onbveforeload event is a static function to send a confirmation message when the user tries to close the window
export class WindowCloseNotifierHelper {
public static setMessage( message: any ) {
if ( message && _.isFunction(message) ) {
window.onbeforeunload = message;
} else if ( message ) {
window.onbeforeunload = ( e: any ) => {
if ( e ) {
e.returnValue = message;
}
return message;
};
} else {
window.onbeforeunload = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment