mirror of
https://github.com/ritz078/transform.git
synced 2026-11-28 03:44:22 +03:00
Implementing an alert before user tries to exit the tab/browser to avoid losing changes made in the editor
This commit is contained in:
1 parent
f3f2bf1373
commit
9f8250c40e
1 file changed
+9
@@ -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");
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user