Skip to content Skip to sidebar Skip to footer

Exit Popup Not Working

I'm trying to get an exit popup to work. When user closes browser, it asks them if they want to stay or not, and in the background, it starts to redirect already. This code works i

Solution 1:

So you want to redirect the user inside an onbeforeunload event.

It looks like this answer could help you.

Code snippet:

window.onbeforeunload = function(){
    location.assign('http://www.google.com');
    return"go to google instead?";
}

You probably won't ever get exactly what you want, but you'll at least display a prompt, and if the user clicks on OK, it should redirect.

Solution 2:

The easiest, and for everyone most satisfying answer to this question is: don't do that! If a user closes a browser that is the most powerful expression of "i really don't want to stay anymore" so why ask them again?

The only thing worse on the internet are those annoying sites where you click the back button and can't leave the page.

So please don't do such evil evil things with programming.

Post a Comment for "Exit Popup Not Working"