Skip to content

Instantly share code, notes, and snippets.

@francescom
Created November 15, 2021 11:35
Show Gist options
  • Save francescom/25baec5d6450c7f65bd189f731299cb7 to your computer and use it in GitHub Desktop.
Save francescom/25baec5d6450c7f65bd189f731299cb7 to your computer and use it in GitHub Desktop.
JS to confirma page close/leave
window.onbeforeunload= (e)=> {e.returnValue="This page is asking you to confirm that you want to leave - data you have entered may not be saved."}
@francescom
Copy link
Author

Modern browsers ignore the string (text will be translated in local language).
String is taken from recent FireFox.
returnValue is more supported than preventDefault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment