T
Taras_96
Hi everyone,
I have a couple of questions regarding encodings of javascript.
Say I have a function getCodePoints in foo.js:
-----------------------------------------------------------
function getCodePoints(str)
{
for(var i = 0; i < str.length; i++)
{
alert(str.charCodeAt(i));
}
}
-----------------------------------------------------------
In my html, which is saved in *UCS-4 (4 bytes per character)*, I
write:
<body onload="getCodePoints('hello');">
How does javascript know that the string it is given is encoded using
UCS-4? Is it transcoded by the browser into javascript's native UTF-16
before giving it to the javascript function?
Equivalently, say we have the following function in a javascript file
which itself is encoded in UCS-4:
function insertString()
{
window.document.getElementById('bar').innerHTML = '¼Ø';
}
And the HTML page which is the target for insertion itslef is encoded
in UTF-8:
<script charset="UCS-4" src="theSource.js"></script> <!-- telling the
browser that the JS is encoded in UCS-4 -->
<body>
<div id='bar'>
</div>
</body>
How does the string get inserted into the HTML with UTF-8 encoding? Is
it again something the browser does (ie, it does something along the
lines of convert the UCS-4 string into javascript's native UTF-16, and
then when writing it into the DOM converts it into UTF-8)?
Thanks
Taras
I have a couple of questions regarding encodings of javascript.
Say I have a function getCodePoints in foo.js:
-----------------------------------------------------------
function getCodePoints(str)
{
for(var i = 0; i < str.length; i++)
{
alert(str.charCodeAt(i));
}
}
-----------------------------------------------------------
In my html, which is saved in *UCS-4 (4 bytes per character)*, I
write:
<body onload="getCodePoints('hello');">
How does javascript know that the string it is given is encoded using
UCS-4? Is it transcoded by the browser into javascript's native UTF-16
before giving it to the javascript function?
Equivalently, say we have the following function in a javascript file
which itself is encoded in UCS-4:
function insertString()
{
window.document.getElementById('bar').innerHTML = '¼Ø';
}
And the HTML page which is the target for insertion itslef is encoded
in UTF-8:
<script charset="UCS-4" src="theSource.js"></script> <!-- telling the
browser that the JS is encoded in UCS-4 -->
<body>
<div id='bar'>
</div>
</body>
How does the string get inserted into the HTML with UTF-8 encoding? Is
it again something the browser does (ie, it does something along the
lines of convert the UCS-4 string into javascript's native UTF-16, and
then when writing it into the DOM converts it into UTF-8)?
Thanks
Taras