在IE9和IE11上呈现不同的IFrame

时间:2015-11-24 09:16:31

标签: javascript jquery xml asp.net-mvc iframe

我使用表单和iframe创建了传统的文件上传。我的HTML:

<form id="theuploadform">
    <div class="form-group">
        <input id="importFile" name="file" size="50" type="file" />
    </div>
</form>

javascript:

var iframe = $('<frame name="postiframe" id="postiframe" style="display: none"></frame>');
$("body").append(iframe);
var form = $('#theuploadform');
form.attr("action", "/uploadhandler.ashx");
form.attr("method", "post");

form.attr("encoding", "multipart/form-data");
form.attr("enctype", "multipart/form-data");

form.attr("target", "postiframe");
form.attr("file", $('#userfile').val());
form.submit();

现在它会发布到UploadHandler.ashx,它会将文件的内容写入iframe:

context.Response.ContentType = "text/plain";
context.Response.Write(new StreamReader(file.InputStream).ReadToEnd());

我的问题是在ie9和ie11上iframe内容的呈现方式不同。

IE11:

<iframe>
<!DOCTYPE html>
<body>
<pre>
// xml content here //
</pre>

IE9:

<iframe>
<Nodename xmlns:xsd="http://www.w3.org/2001/XMLSchema">

是否有任何想法让iframe与IE11相同?

修改

我的_Layout.cshtml上有以下代码:

<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

1 个答案:

答案 0 :(得分:1)

尝试为IE添加元标记:

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

它会根据最新版本的标准强制浏览器呈现。就像在谷歌的CDN上使用最新版本的jQuery一样,这是最新的,但也可能会破坏你的代码,因为它不是固定版本。

或者您可以使用IE9更具体:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />

<meta http-equiv="X-UA-Compatible" content="IE=IE9" />

查看here的详细答案。