I currently have working code that checks for a cookie and if found, it won't show a block of HTML code. If not found, it shows the code and then sets a cookie to expire in 24 hours.That's pretty simple. I wan't to elaborate on it though and now show that block of HTML code the first 3 visits in a 24-hour period. On the 4th visit in 24-hours, I don't want to show that code. I started writing javascript that would check for 3 different cookies and it got to be too much for me. I wonder if there is an easier way. Here's what I have today:
<script type="text/javascript">
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
return unescape(dc.substring(begin + prefix.length, end));
}
var thecookie='bd3b5cookie';
var myCookie = getCookie(thecookie) ;
if (myCookie == null) {
console.log("not found");
//add html content here
}
else {
console.log(" found");
//dont show html code
}
</script>
<script type = "text/javascript">
//set cookie
var now = new Date();
var time = now.getTime();
time += 3600 * 8000;
now.setTime(time);
document.cookie = 'bd3b5cookie=ok;expires='+now.toGMTString()+';path=/';
//console.log(document.cookie);
</script>