开发者

IE iframe and unicode text

I have troubles with iframe in IE. I'm trying to create iframe dynamically and to assign its src attribute to appropriate file according to user selection. I've created a simple html page with inline javascript that reproduces the problem.

<html>
  <head>
    <script type="text/javascript">
      function createIFrame(){
        var iframe = document.createElement('iframe');  
        document.body.appendChild(iframe);
        iframe.id = "myframe";  
      }

      function loadFile(fileName){
        var frame = document.getElementById("myframe");
        frame.src = fileName;
      }
    </script>
  </head>
  <body>
    <input type="button" value="create iframe" onclick="createIFrame()" />
    <input type="button" value="load ansi" onclick="loadFile('ansi.txt')" />
    <input type="button" value="load unicode" onclick="loadFile('unic.txt')" />
    <hr/>
    <iframe id="workingFrame" src="unic.txt"></ifram开发者_JAVA百科e>
  </body>
</html>

ansi.txt - text file saved in ANSI encoding, unic.txt is unicode text file.

Pressing create button iframe is added to DOM. If 'load ansi' button is pressed file content is loaded into iframe without any issues, but 'load unicode' button causes a problem - iframe stays empty.

But if src attribute is defined initially like in case of 'workingFrame' - unicode file is loaded correctly. This issue happens in IE 8, IE 9 suggests to download file instead of rendering it. I need file content to be rendered inside the iframe.


What MIME type is your server sending on this response? What CHARSET does the Content-Type HTTP header specify?

If you send text/html instead of text/plain, I bet this works without error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜