A Better Exit Pop Script

A while ago, some browsers stopped handling exit pops the way the used to.  Instead of popping up your lightbox or whatever splash you were using, it would now throw a generic “are you sure you want to leave” alert and then, only after they clicked saying they didn’t want to leave, it would let you show your splash, which most people have been trained not to do.

What Nickycakes started using was a mouse-out script, that would pop up whatever you want as soon as the user moves their mouse to the back button in the browser.  There are drawbacks to this method.  The biggest being that it doesn’t really do anything on mobile, and won’t fire if the user uses the back button on their mouse, or if they use a key-combo to navigate, but your general dumb internet user still manually clicks the back button.

A simple jquery script is all you need to easily add this to your site.  Nicky has been using it on some sites with great success:


A few notes on what’s happening in the code:

The exitpopped variable makes sure it only fires one time.  The showpop and setTimeout make it so it will only fire after the user has been on the page for 3 seconds (you can change the delay with the delay variable).

As for what to put in your exit pop, there are tons of options.  Most popular would be popping up an email opt-in form, or a lightbox with some kind of discount or special offer.

Added to this post is some javascript to show this in action by popping up the subscribe form so you can see how it works.  Just move your mouse up to the url bar in your browser and it should pop-up the subscription form for this blog (feel free to subscribe as well!)


Peanut Gallery

  • A 1 hour cookie would be a nice addition, in case people are clicking around reading loads and getting pissed with the popups.

    • Really good point. With my implementation that I use, I set a cookie with php, and only show the JS if the cookie isnt set, but it’s doable all in javascript as well.

  • What the fuck do you mean by “your exit pop code here!” ??
    How do you customize this thing?

    • If you’re asking that question, then you probably have no use for this script anyway, but that’s where you put the javascript for showing the actual exit pop, be it a lightbox, or a whole-page overlay, or whatever.

Add a new comment