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;