Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Dynamic IFrame and Charset

  1. #1
    Join Date
    May 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Dynamic IFrame and Charset

    Hi every body!!
    I'm creating an application that uses JavaScript, AJAX and IFrames. A complete example is when you mouseover for a while on an element to see its popup: it sends a HTTPRequest and writes it response to a dynamically generated IFrame. It's something like:

    Code:
    var if = document.createElement('iframe');
    if.src='about:blank';
    // here I use another func that tells which is the document, depending on 
    // browser type and version, using object detection
    var doc = getDocument(if);
    doc.write(content);
    doc.close();
    My problem is that charset is not set correctly: it has UTF-8 and I want it to be iso-8859-1. I've tried with META inside the HEAD of the HTTPResponse, adding this META dynamically to HEAD, adding charset='iso-8859-1' to the script tag, modifying document.characterSet (but it's readonly) and adding Accept-Charset to HTTPRequest header. None of these actions gave me the desired result.

    Some info that may help to help me is that, in other process than informational popup (ie, editing the element), there is the same problem, but when you submit the form to see the confirmation page, it has the correct charset. The form is targeted to the same IFrame and there is no Javascript linked to the submit event.

    żAny idea on this issue? As you can see, I've been looking for a solution in different ways, also with an intensive googling. But I couldn't find anything. Neither related problems on forums nor blogs. It seems as I'm the first having this problem... I can't believe it!!

    Ah! The solution may not include to change the AJAX+IFrame process to a IFrame-only based system.

    Thanks a lot in advance!

    emi

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by emi View Post
    change the AJAX+IFrame process to a IFrame-only based system.
    That would be the simplest, as your experience already shows. If you have control over the server or just access to a method (like .htaccess) that can set a few things for a site or a directory, you could direct the server to serve the files as whatever character set you please.

    Without that, you could try using character entities to represent the non-standard characters.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    emi (05-07-2008)

  4. #3
    Join Date
    May 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have access to apache. What do you say I can test?

    thanks for speed, John!

  5. #4
    Join Date
    May 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks a looooot!!!!
    I added DefaultCharset iso-8859-1 and restarted apache2.

    It worked!!

  6. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't understand your question. I didn't really say to 'test' anything. Except perhaps when I said:

    Without that, you could try using character entities to represent the non-standard characters.
    Is that what you are asking about? For example, if the copyright symbol is giving you problems, use:

    Code:
    ©
    instead. All characters that are outside a character set's repertoire can usually be represented by named or numbered entities. If the import is via text, these will usually be preserved as entities and then interpreted according to the 'top' page's encoding. However, since you are using an iframe, that might not work, as the iframe is technically its own window. So, you might consider importing directly to the document and abandoning the iframe except for when it comes time to submit the form.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #6
    Join Date
    May 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I know, but I'm not able to change tons of code (more than 400 000 lines plus data in DB) to print characters as their HTML code.

    HTTP server side changes were very well.

    What I don't understand is why just this IFrame went into a bad charset. All other IFrames were ok.

    Thanks, john!
    Last edited by emi; 05-07-2008 at 02:03 PM.

  8. #7
    Join Date
    May 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ummhhhh....
    I've been testing it a little bit more and I found another issue... bug:
    It shows ok special characters, but it still have UTF8 as chrset on its document attribute. And you get strange behaviour when you submit the form having wrote some special characters inside form elements. So, text is shown with iso-8559-1 charset, but INPUT form elements get info with UTF8.

    Strange....
    Last edited by emi; 05-07-2008 at 02:21 PM.

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, if you are sending a request to the server using javascript, it will serve the page as it has been requested, which is limited to an extent by the capabilities of the browser. Mozilla (FF and others), and some other browsers can specify mime type and encoding in the request, IE cannot. So you get the server's default encoding for the data type being requested.

    There are various ways this can be set on a server. It goes by the file extension of the page being requested. Whole pages served to the browser in the normal way can often override this setting with their meta content tag. Servers can override this feature, but most do not.

    Making an HTTP request to an iframe gives you even less control (on the client side) over the outcome, as page headers (DOCTYPE and the entire head section in HTML) are generally ignored by the server in this type of request, and when included are ignored by the browser, as the page already has a head section.

    If you did have the proper meta content tag in the head of your requested document, it might trigger the browser's selection of character set once the document was loaded into the iframe, but I wouldn't count on it, and it sounds like you already tried that without success.

    Now, when you ask:

    What I don't understand is why just this IFrame went into a bad charset. All other IFrames were ok.
    Do you mean that other iframes filled via AJAX are not giving you this trouble?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #9
    Join Date
    May 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Do you mean that other iframes filled via AJAX are not giving you this trouble?
    Not really. They are filled up with Javascript, but not AJAX.

  11. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you've encoded the pages properly using the meta tag then and that still doesn't work, try setting the default encoding on the server for that file type.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •