View Single Post
Old 09-14-2010, 07:50 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
You need to set a cookie. Many examples have been posted in this forum - here is one of them. You set the expiry date to the desired number of days ahead (here 365 days - change yours to 1 or whatever).

Code:
<html>
<head>
<title>Welcome Message Displays Once Only</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

</script>

</head>
<body>
<script type="text/javascript">
if(!readCookie('visitedPreviously')){
document.write(' Your Message Goes Here And You See It Only Once ');
createCookie('visitedPreviously', 'visitedPreviously', 365);  // 365 days persistence
}

//eraseCookie('visitedPreviously');  // FOR TEST PURPOSES

</script>
</body>
</html>
Note that "a day" means 24 hours, not exactly the same thing as the next day starting at midnight.


Quizmaster: What is the only prime number between 75 and 80?
Contestant: 99

Last edited by Philip M; 09-14-2010 at 08:11 AM..
Philip M is online now   Reply With Quote