Forum Moderators: open

Message Too Old, No Replies

setting a javascript cookie

how to set a cookie that self expires

         

JRooney

4:00 pm on Oct 24, 2006 (gmt 0)

10+ Year Member



I am no Javascript expert at all. I am looking to create a cookie that will expire in 4 hours.
During that time, if a visitor, with the cookie on their box, returns to the site, a video promo will not play. However if it is their first visit (without cookie) or if cookie has expired, the video will play and a cookie set on their box.

There are a ton of scripts out there but didn't know if anyone had one they knew worked (along with an explanation of the elements and what they mean) that I could make some changes to. Thanks

eelixduppy

7:08 pm on Oct 26, 2006 (gmt 0)



Welcome to WebmasterWorld JRooney,

Here's a real quick example using javascript:


<script type="text/javascript">
<!--
if(document.cookie == "visited=yes") {
alert("You have been here!");
} else {
document.cookie = "visited=yes";
alert("This is your first time here!");
}
// -->
</script>

JAB Creations

11:21 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A HUGE warning: Safari does not accept JavaScript cookies.

There is absolutely no correct justification for this at all! Testing Konquerer will lure you in to a false sense of security as it does not suffer from this handicap. I do not know if they were intelligent enough to fix this issue in the latest version that ships with the latest version of OS X.

*Edit* I would highly recommend setting the cookie via serverside scripting as those cookies are accepted.

- John

[edited by: JAB_Creations at 11:22 pm (utc) on Oct. 26, 2006]