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:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

<script>

exitpopped=0;

showpop=0;

delay=3000;

setTimeout(function(){showpop=1;},delay);

$(document).mousemove(function(e){

if(e.clientY<=5&&exitpopped==0&&showpop==1){

exitpopped=1;

alert("your exit pop code here!");

}

});

</script>

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!)

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.