Aaron Moodie
Aaron Moodie

Reputation: 1965

Safari javascript cookie issue

I've hit a bit of a weird issue in Safari in regards to setting a js cookie. The cookie itself is just a rgb colour value, which gets set using .click(), and is working fine in Chrome and Firefox, yet in Safari the value of the cookie is incomplete, showing up as rgb(193 instead of rgb(193, 184, 76) as the other browsers do.

The jQuery function I'm using to set the cookie is:

$('.project_link a').click(function() {
    var link_colour = $(this).css("color");
    document.cookie = "colour="+link_colour+";expires=;path=/";
});

Upvotes: 2

Views: 3080

Answers (1)

Autodidact
Autodidact

Reputation: 768

Its truncating at the comma. Same thing can happen with semi-colons. Encode it with something like encodeURIComponent.

Upvotes: 5

Related Questions