我使用表单和 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());
我的问题是 iframe 内容在 ie9 和 ie11 上呈现不同。
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" />
最佳答案
尝试为 IE 添加元标记:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
它强制浏览器按照最新版本的标准进行渲染。就像在 Google 的 CDN 上使用最新版本的 jQuery 一样,这是最新版本,但也可能会破坏您的代码,因为它不是固定版本。
或者您可以更具体地使用IE9
:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
或
<meta http-equiv="X-UA-Compatible" content="IE=IE9" />
查看here的详细答案.
关于javascript - IFrame 在 IE9 和 IE11 上的渲染方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33889623/