javascript - IFrame 在 IE9 和 IE11 上的渲染方式不同

标签 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());

我的问题是 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/

相关文章:

jquery - Backbone Marionette 区域 + 布局 + View 层次结构和响应能力

javascript - 在任何地方使用 JavaScript 变量

xml - 基于nodeName的xpath选择

javascript - 文本框中自动完成

javascript - 在 AngularJS 中打开新窗口或新选项卡时停止、启动和销毁间隔

jquery - 间隔触发点击

java - SAXParserFactory 与XMLReaderFactory 的区别。选择哪一个?

java - 为什么 Palantir QS 3.8 无法识别其自己的 XML 导出?

javascript - 使用 HTML 将待办事项列表数据保存到本地存储

javascript - Google Forms 应用程序脚本通过 ID 访问元素 - 无响应 - 不会向项目添加选择