and
and

Reputation: 87

Javascript does not display non-standard characters

So this is the code:

<script type="text/javascript" charset="UTF-8"> 
    function loadScript("http://www.qppstudio.net/individualdays/noscroll/2012-08-15.js") { 
        document.write('<script type="text/javascript" charset="UTF-8" src="', url, '">', '<', '/', 'script>'); 
    }   
</script>

Included in page header:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Page displays unicode characters without any problems expect for the part where posted javascript writes to page. Is the script changed somehow while being downloaded between different domains?

Upvotes: 1

Views: 154

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328604

Probably. This is the first time that I've seen the charset attribute. I'm not sure what you try to achieve with it. If the server sends you file with iso-latin-1 encoding but you tell the browser the file has UTF-8 encoding, what should happen? The browser won't convert the file from one encoding to the other; the best that you could hope for is that the browser tries to interpret the byte stream as UTF-8 which will not work.

The correct solution is to configure the server to send the files with the correct encoding in the HTTP response header. The browser will look for this information and read the byte stream with the encoding specified there.

Don't forget to actually send the bytes in the correct encoding! This means: File reading, copying to the output stream + setting the encoding headers, everything must work perfectly or you will have odd bugs.

Upvotes: 4

Related Questions