From a098da6f09f781f05c302303c51c8c11d831b44d Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 18 Jan 2023 15:05:59 +0100 Subject: [PATCH] moved to before-unload event --- js/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/main.js b/js/main.js index 285a246..1b267af 100644 --- a/js/main.js +++ b/js/main.js @@ -1,5 +1,5 @@ // Handle server connection -document.body.onunload = () => { +window.addEventListener('beforeunload', () => { if (user.connected) fetch('/disconnect', { method: 'POST', @@ -11,7 +11,7 @@ document.body.onunload = () => { id: user.id }) }).then(res => {}); -}; +}); fetch('/connect').then(res => { if (res.status === 200) { user.connected = true;