Welcome visitor
* Login
* Register
It is currently July 15th, 2019, 8:06 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  how can i add and use cookies for my website?
PostPosted: October 17th, 2009, 12:35 am 
User avatar

Posts: 70
Do you know a way to use cookies to find how many times a user visits my page? Im looking for an easy and free way to do it using javascript. Thank you.


Top
 Profile  
 
  Re: how can i add and use cookies for my website?
PostPosted: October 17th, 2009, 1:08 am 
User avatar

Posts: 137
Got this from the web
<script type="text/javascript">
function getCookie(thecookie)
{
if (document.thecookie.length>0)
  {
  namestart=document.cookie.indexOf(thecookie + "=");
  if (c_start!=-1)
    {
    namestart=namestart + thecookie.length+1;
    nameend=document.cookie.indexOf(";",namestart);
    if (nameend==-1) nameend=document.cookie.length;
    return unescape(document.cookie.substring(namestart,nameend));
    }
  }
return "";
}
function checkCookie()
{
visits=Number(getCookie('leaf'))+1;
if (visits!=null && visits!="")
  {
  alert('This is your visit '+visits);
  }
setCookie('leaf',visits,'30');
}
function setCookie(thecookie,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=thecookie+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
</script>
<body onload="if (getCookie('leaf')==0){setCookie('leaf',0,'30');}checkCookie();">


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron