简体   繁体   English

Javascript不显示非标准字符

[英]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. 页面显示unicode字符,对于发布的javascript写入页面的部分没有任何问题。 Is the script changed somehow while being downloaded between different domains? 在不同域之间下载时脚本是否以某种方式更改?

Probably. 大概。 This is the first time that I've seen the charset attribute. 这是我第一次看到charset属性。 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? 如果服务器向您发送带有iso-latin-1编码的文件,但是您告诉浏览器该文件具有UTF-8编码,那会发生什么? 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. 您可能希望的最好的是浏览器尝试将字节流解释为UTF-8 ,这将无法正常工作。

The correct solution is to configure the server to send the files with the correct encoding in the HTTP response header. 正确的解决方案是将服务器配置为在HTTP响应头中发送具有正确编码的文件。 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. 这意味着:文件读取,复制到输出流+设置编码标题,一切都必须完美,否则你将有奇怪的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM