From 50e6108012d93b2069140eac18dcbe2f01e68e1b Mon Sep 17 00:00:00 2001 From: John McCambridge Date: Wed, 17 Apr 2019 16:42:36 -0500 Subject: [PATCH] Add confirmation for closing window (#463) * Add confirmation for closing window * Make function an event listener for consistency * Change let to const * Refactor for compatability --- packages/ide/src/client.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ide/src/client.ts b/packages/ide/src/client.ts index 1cfce075..63f91bde 100644 --- a/packages/ide/src/client.ts +++ b/packages/ide/src/client.ts @@ -34,6 +34,12 @@ export abstract class IdeClient { this.loadTime = time(2500); let appWindow: Window | undefined; + + window.addEventListener("beforeunload", (e) => { + e.preventDefault(); // FireFox + e.returnValue = ""; // Chrome + }); + window.addEventListener("message", (event) => { if (event.data === "app") { appWindow = event.source as Window;