Don't close me, bro!

I have a problem. It happens when I can’t decide immediately what key-command I am suposed to do so next my hands just guess which muscle memory to execute. Often that is ⌘ + W, because I close tabs, a lot. It also happens when I think the focus is on Chrome, but really it’s over on Canary so I close the webapp I was working on.

A lot of times accidentally closing tabs isn’t a big deal ⌘ + Shift + T will open it right back up. But what if you were testing a certian state on that application? You have to reopen the tab and navigate all the way back to where you were. What if you were attending an online conference, DJ-ing on plug.dj, or listening to a video? What if you miss the W key and smack the Q key and close Chrome all together? It’s not a huge problem, but it is an annoying one. So I made a bookmarklet to help prevent it.

Don’t Close Me, Bro!

Just drag it into your bookmark bar and click it when you’re on the tab you don’t want to accidentally close. I use it all the time and it saves me at lease once a day. When you try and close the tab you get a dialog box that says “Whoa bro, you tried to close me. Did you mean to do that?”

Here’s the code:

//"javascript:" is specifically for the bookmarklet
javascript:(function () {  
      window.addEventListener('beforeunload',function ( ) {
          return 'Whoa bro, you tried to close me. \n Did you mean to do that?';
      })
  })();