Popup Ad Cookies

Thursday October 18, 2007

By request, here's some instructions for adding cookies to the popup ads to prevent the ads from popping up more than one time per browser session.

The function that starts the popup needs to check to see if a cookie exists and act accordingly. For the fly-in layer ad, the function startAp() is where we will be working, and for the fade-in layer ad, it will be the function startAf(). We need to wrap an if statement around the two lines within the function so the function only starts the popup if the condition is true.

So here's the code we need to insert as a replacement for the two lines originally in the function...

if(document.cookie.indexOf('popup') < 0) {
	document.cookie = 'popup=yes; path=/;';
	setLeft();
	showAp();
}

Ok, so first we wrap an if statement around the two lines within the function that checks to see if a cookie named "popup" has been set. If the cookie has been set, the statement will prevent the popup from continuing. If the cookie has not been set, the statement will proceed with the popup process by setting a cookie and continuing on. The cookie that is set will prevent the popup from appearing any more during the current browser session.

NOTE: The example above is for the fly-in layer ad, make sure you change the showAp(); line to showAf(); if you are using the fade-in popup. Also, this cookie does not have an expiration date set, so it will be removed by default when the browser is closed. If you want the cookie to exist until a specified time, you need to set the expiration date.

Please refer to this site for more on cookies.. http://www.quirksmode.org/js/cookies.html

comments 1 Comments | days old 6255 days old | Direct Link

milojko
a problem
Saturday February 16, 2008

Hi, Is this the right code:

function startAp() { if (document.cookie.indexOf('popup') < 0) { document.cookie = 'popup=yes; path=/;'; setLeft(); showAp(); } } If it is, it doesn`t work for me ...

post comment Post a Comment

COMMENTS CLOSED DUE TO SPAMMERS
Nobody is going to buy your viagra and gucci bags just because you post 1000 links on an obscure blog!
Contact me if you want to post a comment