Created
April 21, 2016 09:43
-
-
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
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
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