SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Bliesen
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question document.write into iframe changes charset of contained form to UTF

    Yeah, it's as complex as it sounds :P

    Okay, here's the situation: I have a window (it's a modal dialog as well, but let's ignore that for now), where I need to write data into an iframe. Dynamically generated data. This data contains a form, this form is then sent to a server process, which expects it to be latin1 (iso-8859-1). It arrives as UTF-8. I have set the charset both in the container html (which contains the iframes) and the iframe in question to latin1, I once toyed with accept-charset of the form as well, all was ignored. So I started to recreate the experiment step by step.

    HTML, meta tag text/html charset=iso-8859-1, FORM directly in it --> data is sent as latin1
    Next I put the HTML for the form into its own HTML, put an iframe into the first documented and had its src point to the new HTML. Both the new and the old HTML had charset meta tags. Form was loaded into iframe, sent properly as latin1.
    I removed both metatags, we're still sending as latin1.
    Next I thought it might have something to do with the dynamic nature of the iframe filling. I only assigned the iframe's src at runtime. Still, latin1.
    Then I took the final step, and instead of reading an html into the src of the iframe, I wrote the code into the iframe with document.write. Everything LOOKED the same, but the server now receives the form data as UTF-8.

    For this experiment I am using IE 5.5 (it is our compatibility base, another browser is not an option unfortunately - I'm a straight firefox man at home), and yes, the content has to be written into the iframe dynamically. I cannot create a temp file that I would load into it, or I would much rather not (it's a rather complex performance issue)

    To clarify: Soon as I'm using document.write, all meta tags and or accept-charset (or what it was called) for the form are ignored completely.

    I googled a lot, but couldn't find anything like this anywhere. If anyone had any advice at all, I'd be much obliged.

    Daniel

  2. #2
    SitePoint Member porkface's Avatar
    Join Date
    Jul 2003
    Location
    Oregon, USA
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bringah
    Yeah, it's as complex as it sounds :P

    Okay, here's the situation: I have a window (it's a modal dialog as well, but let's ignore that for now), where I need to write data into an iframe. Dynamically generated data. This data contains a form, this form is then sent to a server process, which expects it to be latin1 (iso-8859-1). It arrives as UTF-8. I have set the charset both in the container html (which contains the iframes) and the iframe in question to latin1, I once toyed with accept-charset of the form as well, all was ignored. So I started to recreate the experiment step by step.

    HTML, meta tag text/html charset=iso-8859-1, FORM directly in it --> data is sent as latin1
    Next I put the HTML for the form into its own HTML, put an iframe into the first documented and had its src point to the new HTML. Both the new and the old HTML had charset meta tags. Form was loaded into iframe, sent properly as latin1.
    I removed both metatags, we're still sending as latin1.
    Next I thought it might have something to do with the dynamic nature of the iframe filling. I only assigned the iframe's src at runtime. Still, latin1.
    Then I took the final step, and instead of reading an html into the src of the iframe, I wrote the code into the iframe with document.write. Everything LOOKED the same, but the server now receives the form data as UTF-8.

    For this experiment I am using IE 5.5 (it is our compatibility base, another browser is not an option unfortunately - I'm a straight firefox man at home), and yes, the content has to be written into the iframe dynamically. I cannot create a temp file that I would load into it, or I would much rather not (it's a rather complex performance issue)

    To clarify: Soon as I'm using document.write, all meta tags and or accept-charset (or what it was called) for the form are ignored completely.

    I googled a lot, but couldn't find anything like this anywhere. If anyone had any advice at all, I'd be much obliged.

    Daniel
    I don't know **** about Character sets, but try setting the document.charset, document.defaultCharset, and/or document.characterSet properties before you do the document.write.

    IE might send using the desired character set if those values are properly set.

    Also, please don't forget to post results back here because I'm pretty curious.

  3. #3
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Bliesen
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I solved it in a peculiar way after all. I wrote the content that was previously written by document.write into a variable in the top iframe containing html, read that variable from the innermost iframe and on a timeout, had that iframe overwrite its whole body with (bodyobj).innerHTML = thatvariable. That worked and the charset specified in the metatag was now properly read. Weird stuff.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •