Login Register

Encoding considerations

The two most important aspects of internationalization are insuring that the inputs and the outputs are in the proper encoding. Thankfully, UTF-8 encoding can be used exclusively on the wire in modern web applications to make this interaction extremely simple. Once read into memory, JavaScript treats all strings as a series of double-byte characters and encoding is irrelevant. Dojo makes no attempt to implement any encoding or decoding algorithms in JavaScript; this is the responsibility of the browser.

Other encodings should be used with great care. A user agent such as one of the current generation browsers infers the encoding of a page using the content-type header provided by a server or it may be picked up from a meta tag in the head of a document, such as the following:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

The most common means of specifying the encoding in a page is to use the META tag. Note that the META tag only works in pages loaded directly by browsers or IFRAMEs and may not function when used in other situations, such as in a document referenced by HREF in dijit.layout.ContentPane. UTF-8 is the detault encoding used by XML documents exchanged by the XmlHttpRequest object and also is the encoding that is used internally by Dojo APIs such as dojo.io.bind. We recommend using UTF-8 as the encoding for all of your applications.

It is important to properly specify the encoding of the page when forms or form widgets are present as the page's encoding is used to properly encode data that is sent back to a server.



setHref with Encoding

Hi, My chinese character set seems to be working well under normal conditions, but when (in index.htm) I use setHref to load the page: dijit.byId("clientPane").setHref('page.htm');
and I stick


in page.htm, the chinese content does not appear correctly. It *does* appear ok in index.htm, and it *does* appear correctly if I load page.htm directly in the browser, so I suspect setHref might be sending a different content-type? Is there a way to change this please?

Content Pane doesn't honor META tags

...as far as I know. If you deviate from UTF-8 encoding, you need to make sure the actual HTTP headers reflect your gb2312 encoding. The META tag will work anywhere the browser processes an HTML page, but if pages or page fragments are processed by Dojo (in JavaScript), it won't work. Dojo does not do any encoding, decoding, or conversions in JavaScript. All encoding is done by the browser or XHR. I'll have to clarify this somewhere in the docs. Thanks.

explicit UTF-8 declaration required when using xdloader/cdn

When using the xdLoader, UTF-8 encoding MUST be specified using a META tag. This is because the xdLoader uses SCRIPT tags to load content from the content delivery network (CDN) rather than XHR, which assumes UTF-8 encoding by default.