Welcome to WebmasterWorld Guest from 54.163.25.166

Forum Moderators: open

Message Too Old, No Replies

Javascript Cookie Help

     
7:59 am on May 20, 2007 (gmt 0)

Full Member

10+ Year Member

joined:June 16, 2004
posts:232
votes: 0


I want the script to do the following

1) Get postid through voting function
2) Check to see if the cookie voteids exists
3) If not create cookie voteids with a value of postid with a underscore char
4) if cookie does exit add postid with underscore after the current cookie value

function voting(postid)
{

if (document.cookie.length > 0)
{
var begin = document.cookie.indexOf(voteids+"=");
if ( begin!= -1)
{
begin += voteids.length+1;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = document.cookie.length;
}
var ids=document.cookie.substring(begin, end);
ids +=postid+"_";
document.cookie = "voteids="+ids+"_";
}
else
{
document.cookie = "voteids="+ids+"_";
}

}
else
{
document.cookie = "voteids="+ids+"_";
}

}

5:49 pm on June 2, 2007 (gmt 0)

New User

5+ Year Member

joined:June 2, 2007
posts:6
votes: 0


This should do the job, and ignore duplicates:

function voting(postid)
{
 var cv, dup=false;

 if(document.cookie && (cv=document.cookie.match(/voteids=([^;]+);*/i)) )
  if(cv[1].match(new RegExp('_?'+postid+'([_;]¦$)')))
   dup=true;
 if(!dup)
  document.cookie='voteids='+(cv?cv[1]+'_'+postid:postid);
}
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members