From 5d1e71ee459c93d5f12ec9dbcded145abd2e73ff Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sat, 27 Jul 2024 17:26:54 +0200 Subject: [PATCH] Add beforeunload event to add confirmation dialog when leaving page --- 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();