[Greasemonkey] Javascript character encoding problem

Lenny Domnitser ldrhcp at gmail.com
Thu Apr 6 17:23:55 EDT 2006


On 4/6/06, Jonas Lundberg <my.name.is.hans at gmail.com> wrote:
> no that does not work. It seems that although the page headers can say
> something about the encoding, they do not affect the actual encoding
> of the message.

I was looking through the XMLHttpRequest code (albeit with low
knowledge of C++ and Mozilla), and it seems that it just posts
whatever data it takes in without regard to the stated content-type
charset.

> I noticed that a normal submit (using a submit button) on some pages
> sends the characters scrambled, and on other pages as they should be.
> Thus, using a normal submit, the character encoding depends on the
> page encoding.

Yes, the browser assumes that the form should be sumbitted in the
encoding of the page, unless the form has an accept-charset attribute.
[1] If the source page is encoded in iso-8859-1 and the data is utf-8,
then a form can be set to convert charsets, but XMLHttpRequest cannot
(I think). You may be better off creating an invisible form with the
proper attributes, and submit()ing that, rather than using
GM_xmlhttpRequest.

What is the page's encoding, and where is the data that you are
submitting coming from?

[1]: http://www.w3.org/TR/REC-html40/interact/forms.html#adef-accept-charset


More information about the Greasemonkey mailing list