提交 0873a8b0 编写于 作者: B Benjamin Pasero

web - switch to addEventListener for beforeunload

上级 cb932e42
......@@ -22,12 +22,10 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
}
private registerListeners(): void {
// Note: we cannot change this to window.addEventListener('beforeUnload')
// because it seems that mechanism does not allow for preventing the unload
window.onbeforeunload = () => this.onBeforeUnload();
window.addEventListener('beforeunload', e => this.onBeforeUnload(e));
}
private onBeforeUnload(): string | null {
private onBeforeUnload(event: BeforeUnloadEvent): void {
const logService = this.logService;
logService.info('[lifecycle] onBeforeUnload triggered');
......@@ -48,7 +46,10 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
// Veto: signal back to browser by returning a non-falsify return value
if (veto) {
return localize('lifecycleVeto', "Changes that you made may not be saved. Please check press 'Cancel' and try again.");
event.preventDefault();
event.returnValue = localize('lifecycleVeto', "Changes that you made may not be saved. Please check press 'Cancel' and try again.");
return;
}
// No Veto: continue with Will Shutdown
......@@ -61,8 +62,6 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
// Finally end with Shutdown event
this._onShutdown.fire();
return null;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册