How to show single pop-up for whole guest session In my site I want to place a javascript ad code( from Zedo) which is popping up one window for each page visit by the user which is quite nagging.

Ideally what I want is to pop up the ad after user leaves the site or closes the window.

At least I want is to show single pop up in the whole guest session.

I place the ad code before &lt;/body&gt; in page.tpl.php but it gets executed for every page.

I'm thinking to make it better by using this logic:

if(time() % 3 == 0)
{
//javascript ad code here
}


At least this will reduce pop up by 3 times.

Are there any better ideas?
You can use one cookie, if is the first time to the user enter into your page then create a cookie, when the user change of page you will check if the cookie exists and if exists don't show up the ad.