Skip to content

Instantly share code, notes, and snippets.

@benknight
Last active November 28, 2018 04:41
Show Gist options
  • Save benknight/13595bdd49a6b87c6d24 to your computer and use it in GitHub Desktop.
Save benknight/13595bdd49a6b87c6d24 to your computer and use it in GitHub Desktop.
Before Unload Bookmarklet

Before Unload Bookmarklet

Clicking this bookmarklet on a browser tab will cause the above alert to display when you try to close it. Handy if you have work you really don't want to lose.

javascript:window.addEventListener%28%22beforeunload%22%2C%20function%20%28e%29%20%7B%20var%20confirmationMessage%20%3D%20%22o/%22%3B%20%28e%20%7C%7C%20window.event%29.returnValue%20%3D%20confirmationMessage%3B%20return%20confirmationMessage%3B%20%7D%29%3B
@tzi
Copy link

tzi commented Dec 10, 2015

"work you really don't want to use" => I tkink you meant "to loose".

@benknight
Copy link
Author

I'll strike a compromise with you and change it to: "to lose"! Thanks ;)

@simevidas
Copy link

This is a lifesaver. I often load a ton of tweets into my Twitter timeline, and then accidentally click on a link to another page.

@shmdhussain
Copy link

How to use this? Where i need to paste the code?

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