views:

26

answers:

1

Hi dear stackers,

I'm a bit stuck, given my page includes an external Javascript which uses document.write. The problem is my page is UTF-8 encoded, and the contents written are encoded in latin-1, which causes some display problems.

Is there any way to handle this ?

-- Thanks in advance, Rolf

+1  A: 
T.J. Crowder
I'm not sure that works everywhere; Chrome for example seems to pay attention only to an encoding declaration in a `<meta>` tag in the head, or (maybe) in the DOCTYPE.
Pointy
@Pointy: The `<meta>` tag on the HTML document will control what the charset is for the document. Chrome *should* respect the `charset` of the external script resource. But as I say, I've never actually had to mix charsets like this, just quoting what the specs tell us. :-) The real world may well vary. (I'm actually itching to try it now, but I just don't have time today.)
T.J. Crowder
Yes I'm not very sure on this either. I'd actually prefer that `document.write` didn't exist at all, for this and many other reasons.
Pointy
@Pointy: Yeah. :-) Although again, by the time the `document.write` executes, it's dealing with a UTF-16 string. This `charset` stuff is all about how the script gets *read* -- the actual characters in the JavaScript file itself... But I'm with you on `document.write` regardless.
T.J. Crowder
it works like a charm :)
Rolf
but not with IE :(
Rolf
@Rolf: Sounds like some progress, anyway. Re IE: You're being careful about the `Content-Type` header being returned with the script file? Your server isn't contradicting you?
T.J. Crowder