From e4b0467f9f4b054723528c93c4cda56a266f8687 Mon Sep 17 00:00:00 2001 From: Hanusz Leszek Date: Sun, 29 Sep 2024 06:14:19 +0200 Subject: [PATCH] Add beforeunload event to add confirmation dialog when leaving page (#6279) --- js/main.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/main.js b/js/main.js index 899bd8f0..71489f14 100644 --- a/js/main.js +++ b/js/main.js @@ -600,4 +600,15 @@ headerBar.addEventListener("click", (e) => { } }); +//------------------------------------------------ +// Add a confirmation dialog when leaving the page +// Useful to avoid data loss +//------------------------------------------------ +window.addEventListener('beforeunload', function (event) { + // Cancel the event + event.preventDefault(); + // Chrome requires returnValue to be set + event.returnValue = ''; +}); + moveToChatTab();