PDA

View Full Version : Random pop-up windows and cookies


motokouzi
01-22-2003, 09:02 AM
Hello people!
I'm using the following code in order to have one out of two pop-up windows to appear everytime someone visits a web site. I want to somehow use cookies in order to check if someone has already seen one of the pop-ups (in that case the other pop-up will pop up) and in case he has seen both of them no pop-up will appear for a week. Please help me!!

<SCRIPT LANGUAGE="JavaScript">
//specify URLs to randomly select from and pop-up
var popwin=new Array()
popwin[0]="popa.htm"
popwin[1]="popb.htm"

//specify popwin window features
var winfeatures="width=400,height=300,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0"

//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=0

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function loadornot(){
if (get_cookie('popwin')==''){
openup()
document.cookie="popwin=yes"
}
}

function openup(){
winpops=window.open(popwin[Math.floor(Math.random()*(popwin.length))],"",winfeatures)
}

if (once_per_session==0)
openup()
else
loadornot()

</SCRIPT>