International Language Support in JavaScriptJavaScript is built to support a wide variety of world languages andtheir characters – from the old US ASCII up to the rapidly spreadingUTF-8. This page clears up some of the difficulties encountered whendealing with multiple languages and their related characters.
JavaScript and Character SetsWhen working with non-European character sets ("charsets"), you mayneed to make changes to the way your page references externalJavaScript(.js) files. Ideally, your .js files should saved in theUTF-8 character set in order to maximize its multilingual features —though you can use a different charset that supports your language, atthe potential expense of users who can't support it. Once your filesare saved as UTF-8, they must be "served" in the UTF-8 charset in orderto display correctly. There are a few ways to ensure this:
Serve the Web Page as UTF-8If your page is already served as UTF-8 (i.e. Content-type=text/html; charset=UTF-8),you don't need to make any changes — all embedded files in an HTMLdocument are served in the same charset as the document, unlessexplicitly specified not to by you. You can do this by:
Use the charset attribute of the <script> tagThe easiest way to ensure your script is served as UTF-8 is to add acharset attribute (charset="utf-8") to your <script> tags in theparent page:
<script type="text/javascript" src="[path]/myscript.js" charset="utf-8"></script>Modify your .htaccess files (Apache Only)You can also configure your webserver to serve all .js files in theUTF-8 charset, or only .js files in a single directory. You can do thelatter (in Apache) by adding this line to the .htaccess file in the directory where your scripts are stored:
AddCharset utf-8 .js |