开发者

Cookie with Multiple Values stored

I'm having trouble with cookies. I have a bunch of links that when clicked on, create a cookie. For each link I need to b开发者_Go百科e able to save that cookie value to the main cookie name.

Here is the click function I'm using to create the cookie:

$j('a.createCookie').click(function(e) {
 var cookieName = "InsightsCookie";
 var cookieValue = $j(this).attr("id");
 $j.cookie(cookieName, cookieValue, {expires: 365, path: '/'});     
});

The end result would be "InsightsCookie: cookieValue, cookieValue, cookieValue" - where each link clicked on would add a value to InsightsCookie.

Any help would be much appreciated.


Cookies aren't intended to store structured data.

Typically the cookie has some kind of key value (a random integer, or alphanumerical value, for example) that is unique to that person. The web site uses that cookie to know who is visiting, and then keeps track of all the times/places the person with that cookie goes in some kind of database, thereby building a history.

So, basically, it's typically the web site's job to keep track of that, not the cookie on the user's machine.

If that's not an option for you for some reason, you could simply get the value that's already in the cookie, and then append the new value to it with each visit. If that user visits a lot of pages on your site, the cookie might get too big very quickly. There are restrictions on the maximum size of a cookie, and that's kind of a janky way to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜