Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Javascript character set screw-ups (via) Some browsers treat JavaScript files as having the same content-type as the page from which they are linked. This could cause problems with UTF-8 encoded JSON; the workaround is serving up ASCII with unicode escape sequences.

Tagged , ,

4 comments

  1. Well, he could add a charset="utf-8" attribute to the <script> tags. That fixes the issue in all browsers I've ever come across.

    I don't know about the XMLHTTPRequests (haven't tried) but I bet there's a similar property/method/attribute/thingy that we can use there.

    Már - 22nd December 2006 19:43 - #

  2. FWIW, Internet Explorer 7 fails both 2 and 3. It handles XMLHttpRequest ok. One could argue that Internet Explorer is the browser that's consistent here since browsers generally ignore the Content-Type header for script files. Apparently most still look at the charset parameter though.

    Anne van Kesteren - 24th December 2006 18:20 - #

  3. I've updated the web page with this, but I feel that I shouldn't have to know what charset the remote page is in. For those remote JSON APIs that are called by including a <script> tag, you'd need to make the charset of the remote page part of the public API. Not unreasonable, but (a) no-one will do it, and (b) it feel inelegant.

    Tom Insam - 26th December 2006 15:46 - #

  4. Oh, I totally agree with you. Just pointing out some facts.

    Anne van Kesteren - 26th December 2006 22:18 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site