定义JavaScript源文件的字符编码 [英] Defining the character encoding of a JavaScript source file
问题描述
我想向我的德国用户打印状态消息,其中包含变音符号(ä/ü/ö)。我也希望他们在源文件中,而不是只为了消息下载和解析一些额外的文件。
I would like to print a status message to my German users, which contains umlauts (ä/ü/ö). I also would like them be in the source file rather than having to download and parse some extra file just for the messages.
然而,我似乎无法找到一个定义JS源文件编码的方法。是否有类似HTML的 http-equiv
?或者我应该在HTTP标头中定义编码吗?
However, I can't seem to find a way to define the encoding of a JS source file. Is there something like HTML's http-equiv
? Or should I define the encoding in the HTTP header?
当我简单地用UTF-8编码文件时,IE显示垃圾。
When I simply encode the file in UTF-8 an serve it, IE displays garbage.
推荐答案
在标题中发送编码总是一个好主意。
Sending the encoding in the headers is always a good idea.
如果这不可能,< script>
标记具有 charset
属性。 W3C参考
If that's not possible, the <script>
tag has the charset
property. W3C Reference
<script src="translations.js" type="text/javascript" charset="utf-8"/>
这篇关于定义JavaScript源文件的字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!