[whatwg] Character encoding of document.open()ed documents

Henri Sivonen hsivonen at iki.fi
Wed Mar 31 07:37:59 PDT 2010


On Mar 31, 2010, at 16:24, Boris Zbarsky wrote:

> On 3/31/10 7:12 AM, Henri Sivonen wrote:
>> Currently, the spec says that document.open() sets the document's character encoding to UTF-16. This is what IE does except IE uses the label "unicode" instead of "UTF-16".
>> Demo: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/438
>> 
>> Gecko and WebKit set document's character encoding to UTF-8 even though the parser operates on UTF-16.
>> Demo: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/439
> 
> Is that what Gecko does?  Or does it set the document's character encoding to the character encoding of the page that called open()?  I believe it's actually the latter.
> 
>> When loading external resources that don't have encoding labels, IE, Gecko and WebKit all use UTF-8 to decode the external resource.
>> Demo: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/437
> 
> Again, UTF-8 or the encoding of the page that called open()?

Good point.

Gecko sets the document's character encoding to UTF-8 and uses UTF-8 to decode the external resource. WebKit uses the encoding of the opener. IE8 (both with compat view button pressed and not pressed) sets the document's character encoding to "unicode" and uses UTF-8 to decode the external resource. Opera uses Windows-1252 to decode the external resource.
http://hsivonen.iki.fi/test/moz/document-open-external-charset.htm

>> None of IE, WebKit or Opera let the meta charset in a document.open()ed document have any effect
> 
> As in, it doesn't affect how external resources with no encoding labels are handled?

Right.

> Odd; I could have sworn it mattered in IE.  I distinctly recall Gecko having compat bugs of various sorts here for the external resource case at one point (as in, people reporting intranet apps and the like that worked in IE but not Gecko), and us trying pretty hard to fix them.

It seems to me it doesn't matter even in IE6:
http://hsivonen.iki.fi/test/moz/document-open-internal-charset.htm

(WebKit seems to cache the charset of external resources, so it seems necessary to create a new incognito window in Chrome for each test run.)

-- 
Henri Sivonen
hsivonen at iki.fi
http://hsivonen.iki.fi/





More information about the whatwg mailing list