How do I keep people from accidentally closing my page

so in the game eaglercraft ( when you press the close page button, it gives you a prompt to ask if you are sure if you want to close the game, how do I do that. I only grabbed the code from GitHub (because the website that hosts it doesn’t work anymore) and imported it to replit

window.onbeforeunload = function() {
  return "";

Some older browsers would display the message returned by window.onbeforeunload however modern browsers will ignore this with an unchangable message (which is why we return an empty string)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.