FIX: Unicode .js File Included from SCRIPT Tag Generates Script Error (239948)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5

This article was previously published under Q239948

SYMPTOMS

Internet Explorer reports an "Invalid character" error when a Unicode .js file is included with the SCRIPT tag, for example:
<SCRIPT LANGUAGE="JavaScript" SRC="Sample.JS">
				
If the script debugger is enabled, it reports that the first two characters in the .js file (the Unicode Byte Order Mark, or BOM) are the source of the problem.

Another closely associated problem occurs if the Byte Order Mark is removed from a Unicode format .js file and the file contains Unicode characters. When the .js file is included during page rendering by Internet Explorer, Unicode characters in the .js file are interpreted as simple ASCII and cause either a script error, as above, or the display of garbage characters. Similarly, removing the BOM from a UTF-8 encoded file containing non-ASCII Unicode characters results in garbage characters being displayed on the rendered Web page.

Note that in the Internet Explorer Advanced dialog box (from the Tools menu, select Internet Options), the option Disable script debugging must be cleared or the option Display a notification about every script error must be selected in order to receive a detailed error message for this problem. If these two options are not set correctly, the Internet Explorer status bar indicates that there are errors on the page. The page loads, but the .js file does not.

RESOLUTION

It is possible to work around the problem, in most cases, by embedding Unicode escape sequences in the .js file that is saved in ASCII. For instance, the following JScript statement may be used in an ASCII .js file to specify the Hiragana character NO.
var s = String("Hiragana NO = \u306E");
				
When the ASCII .js file is loaded from the SCRIPT tag there is, of course, no Unicode Byte Order Mark, and the \uXXXX escapes are converted to proper Unicode characters that appear on a Web page.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Internet Explorer 5.5 and Internet Explorer 5.01 on Windows 2000.

Modification Type:MajorLast Reviewed:10/16/2002
Keywords:kbBug kbDSupport kbie501fix kbie550fix kbIntl kbIntlDev KB239948