1

So i wanted to make a small game in javascript to be seen in the browser which includes a database, an user would connect and before he leaves the page would forward the progress of his account on said database.

I visited this question : window.onunload is not working properly in Chrome browser. Can any one help me?

And this one : what can i put in beforeUnload?

Which provided information on unload not being as good as onbeforeunload, returning a string rather than an alert.

I have problems with onunload/onbeforeunload events (before making links with the database i tried just having an alert/returning a string to have a message from the browser : seeing an output from event) which don't seem to work on chrome/safari.

For instance this code only trigger a response on my code editor (Komodo) but no browsers :

window.onbeforeunload = function(){return "Are you sure you want to leave this page?";}

So in the end should i just try with the database to see if i can have a script working in onbeforeunload ?

If anyone has an idea/a solution I would enjoy it very much :)

Simon
  • 11
  • 1
  • Quote https://developer.mozilla.org/en-US/docs/web/api/window/beforeunload_event: _"To combat unwanted pop-ups, browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with, or may even not display them at all."_ – CBroe Apr 27 '22 at 10:31
  • onbeforeunload is such a train wreck - different browsers handle it completely differently, you need to return different types of things in different browsers to make it work, or set some property in the event, or hop 3 times on your left leg while singing the Spanish anthem, and in the end, virtually NO browser displays the message you want to display anyway – Bravo Apr 27 '22 at 10:41

0 Answers0