I\'m looking for a way to display a message to the user if he leaves my site after only viewing one page.
I found this (http://www.pgrs.net/2008/1/30/popup-when-leaving-
I will start by saying that I will not, in any way, recommend that you do this. It's a bad practice, it only annoys users and it makes you look extremely desperate. I repeat, don't do this, it's not a good idea, it's silly and it's not a good idea.
But the way you can do it is to only display the message when users are clicking on links that lead away from the site.
You can do this by looking at the href
attribute of the link and check if it's an external site. If it is, then display the message