[thelist] yet another popup question

Keith cache at dowebs.com
Tue Jan 8 18:42:34 CST 2002


Meridith
> 
> Hopefully this is a quickie...I want to set the cookie on
> this popup so that site visitors will see the popup only
> once every 24 hours; however, I don't know how to change the
> cookie expiration date.  How can I switch it from GMT to a
> 24 hour cycle?

Just roll the Hours method forward 24....

when= new Date()
when.setHours(when.getHours()+24)
expires=when.toGMTString()
document.cookie = "COOKIE1=here;expires="+expires+";path=/"

That will set the cookie expire 24 hours ahead in Greenwich time 
which is OK since the same browser will be measured tomorrow in 
Greenwich time.

While we're at it, may I suggest a simpler way to get and set the 
cookie, you don't need to break the document.cookie string up, just 
look for the name of your unique cookie.

<script language=javascript>
if(document.cookie.indexOf("COOKIE1") == -1){
when= new Date()
when.setHours(when.getHours()+24)
expires=when.toGMTString()
document.cookie = "COOKIE1=here;expires="+expires+";path=/"
}
</script>


keith




More information about the thelist mailing list