[Greasemonkey] Javascript character encoding problem
Jonas Lundberg
my.name.is.hans at gmail.com
Fri Apr 7 16:29:06 EDT 2006
>From your response, it seems that my problem does indeed come from a
javascript bug (or intended, but crippling, limitation).
The problem is the following:
I read some contents (including the html for the form) from my own
server for web2-services. I then inject that into any web page I
visit, through the greasemonkey script. The form contents are sent
back to my web-2 server.
So, my form will not be posted to the server that hosts the page I
view. Therefore, I submit it through ajax - because I do not want to
re-direct the user to my web2 server on submit, the user should stay
on the same page.
Also, different pages will have different encodings, and this should
not affect my form.
So, it is good that the text encoding in the Ajax call does not vary.
But it is BAD that XMLHttprequest does not use utf-8. To hard-code a
non-international character set into a generic technology like
javascript seems odd, to me. Is this what has happened? Is there
really no way to set the encoding that is used?
Regards
Hans
On 4/6/06, Lenny Domnitser <ldrhcp at gmail.com> wrote:
> 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
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
More information about the Greasemonkey
mailing list