我使用表单和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" />
答案 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的详细答案。