First I have this function :
function setCookie (Bezeichner, Wert, Verfall) {
var jetzt = new Date();
var Auszeit = new Date(jetzt.getTime() + Verfall);
document.cookie = Bezeichner + "=" + Wert + "; expires=" +
Auszeit.toGMTString() + ";";
}
then I call it like this:
setCookie('Wert',someValue,123456789);
where someValue consists of Russian characters.
If I look into this cookie using FireFox Display Cookie Tool, there are
already only some badly identifiable characters inside. I could live
with it, as long as I would receive a proper content back, but this is
not the case here...
I evaluate this cookie in a PHP script on the server side thru
$HTTP_COOKIE_VARS, setting a variabe $wert, which gets printed in the
HTML-output. It read just the same what I had seen thru the FF Cookie
Tool before...
Strange enough, I have this problem only in the FF; the Internet
Explorer copes with it easily..
Victor
Martin Honnen wrote:
Victor wrote:
could anybody help me with the following problem :
I need to set a cookie containing a Russian character string as the
value, using the construct "document.cookie = ...". The whole project
runs in the UTF-8 encoding.
The Internet Explorer handles this cookie correctly, whereas the
FireFox writes only some byte gargabe and then reads it back.
Nowadays (since JScript 4 and JavaScript 1.3) strings in JavaScript are
sequences of Unicode characters so a Russian (cyrillic?) character is
just another Unicode character in a JavaScript string. In terms of
string handling a Russian character should not pose any problems.
As for document.cookie, how exactly do you write a value in there, how
do you read it back? Where do you notice "byte garbage"? Do you use the
escape function to escape the cookie value before setting
document.cookie, do you use the unescape function on the cookie value
you get from document.cookie?
--
Martin Honnen
http://JavaScript.FAQTs.com/