Activate pop-up when reader goes to close the browser tab or window

Hi all,

My client unfortunately is insisting on activating a pop-up when a reader goes to close the browser tab or window. You know the type of thing, one that activates when the mouse cursor goes near the close X for the tab or window.

Yes I know they are really annoying! The client is insisting.

Does anyone know how to implement this maybe with a little js?
I already have some js that controls the pop so that it only shows when the reader first visits the site, I adapted a cookie script that was meant to prevent the European cookie policy warning from showing more than once.

Thanks Graham

See these answers and

Thanks Sam,
For anyone reading this post, the above solution is not recommended as per the above reply, see follow-on response below:

Hi Graham,

According to, Google Chrome will display an ugly alert prompt (AND the user has to click on the Stay button) before we can actually display your popup,

so in this case I actually recommend not going this route. If the user clicks on the Leave button, we can’t display the popup…

I’d recommend creating an interaction that when your mouse hovers out of the body element, then the modal shows up.

You’ll want to also create some sort of cookie in your site to prevent it from showing up again after clicking close as well :smiley:

Hope that this is helpful! :bowing_man:


How would I create that cookie?