Answer the question
In order to leave comments, you need to log in
Why are Russian words not added to cookies in safari, but are displayed in opera?
Adding cookies via javascript The data comes via json, so this is the output.
var req = jQuery.parseJSON(json);
var date = new Date(new Date().getTime() + 60*60*24*365*1000*10);
document.cookie = "city="+req.city+"; path=/; expires=" + date.toGMTString();
document.cookie = "id="+req.id+"; path=/; expires=" + date.toGMTString();
document.cookie = "hash="+req.hash+"; path=/; expires=" + date.toGMTString();
document.cookie = "text=казань; path=/; expires=" + date.toGMTString();
Answer the question
In order to leave comments, you need to log in
Before storing in a cookie, encode your string with encodeURIComponent
On reading, decode back with decodeURIComponent
Although modern cookies support Unicode, it's not always possible to write it there.
Check out this article: stackoverflow.com/questions/1969232/allowed-charac...
It all depends on the browser, Safari doesn't save UTF for example. So encode your strings.
To work with Cookies, it is best to use a special library that can do all this out of the box and has a convenient API: https://github.com/js-cookie/js-cookie
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question