Implementing an alert before user tries to exit the tab/browser to avoid losing changes made in the editor

This commit is contained in:
Keshan Nageswaran committed 2018-07-10 19:57:37 +05:30
1 parent f3f2bf1373
commit 9f8250c40e
1 file changed
+9
+9
View File
@@ -81,14 +81,23 @@ export default class Layout extends PureComponent {
this.setKey(this.props.pathname);
}
componentWillUnmount() {
window.removeEventListener("beforeunload", this.alertExistHandler);
}
componentDidMount() {
Layout.loadCarbonAds();
window.addEventListener("beforeunload", this.alertExistHandler);
}
componentWillReceiveProps({ pathname }) {
this.setKey(pathname);
}
alertExistHandler(event) {
event.preventDefault();
return (event.returnValue = "Are you sure you want to close?"); // currently newer version of chrome and other browsers deosn't support customized string so returning a string or empty string won't be of much impact
}
static loadCarbonAds() {
// const script = document.createElement("script");
//