[thelist] weird JS error
Andrew Clover
and-evolt at doxdesk.com
Wed Dec 15 05:55:35 CST 2004
Brian Cummiskey <Brian at hondaswap.com> wrote:
> the firefox JS consoel is throwing me a rather weird validation error.
That string of odd characters is what you get if you try to read in this
ASCII string:
> with (document)
> {
> write('\bVersion: 1.0.0 - 12-13-2004\b');
> }
as UTF-16. Firefox is simply complaining that the odd characters don't
appear to be executable JavaScript of any sort.
The problem is that your web server is serving JavaScript files with the
header:
Content-Type: text/javascript
However this does not tell the web browser what character encoding the
file is using. So it has to guess. Firefox's guess is "the same encoding
as the HTML page that referenced it". And for some reason your HTML page
is saved as UTF-16, an encoding which uses two bytes per character
instead of one, and hence one of the few encodings that isn't compatible
with US-ASCII.
To fix, either make the server specify a character encoding for JS files
by sending a header such as:
Content-Type: text/javascript;charset=utf-8
or save the HTML file in a format compatible with US-ASCII. UTF-8 is a
good choice.
Windows calls the UTF-16 format "Unicode" when you save it, which is
pretty misleading and might have lead to this inappropriate choice of
encdings to save under.
--
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/
More information about the thelist
mailing list