I want to store the href value in a cookie, trouble is when i do the cookie is escaping the forward slashes, so for example
code is
$.cookie ("mycookie", $link.attr("href"), { path: '/', expires: 7 });
html is
<li><a id="czechrepublic" href="/cz/cz.html">Česká republika</a></li>
When i store the href it is being stored as
%2Fcz%2Fcz.html
But i need it to be stored as /cz/cz.html is there a way of UNescaping characters in Jquery, i have seen this in standard javascript cookie tutorials but i am not sure how to do it with the Jquery cookie plugin
Thanks
Joe
$.cookie.raw = true
$.cookie('mycookie','/cz/cz.html')
From here
Use decodeURIComponent(vartobedecoded.replace(/\+/g, " "));
When you retrieve the cookie through the jQuery cookie plugin via $.cookie('mycookie')
, it will automatically be unescaped using the correct function which is decodeURIComponent
.
If you need to decode the string at the server end, you'll have to use the URL-decoding function in whichever language you're using.
If you need to have an unencoded cookie because the server end can't be changed to use encoded cookies, you should forget the jQuery plugin andjust set the cookie yourself:
document.cookie= 'mycookie='+$link.attr("href");
For the value /cz/cz.html
this will be OK, but there are lots of other characters you can't store in a cookie, which is why jQuery escapes them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With