简体   繁体   中英

IFrame rendered differently on IE9 and IE11

I have created a traditional file upload using form and iframe. My html:

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

The 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();

Now it will post to UploadHandler.ashx that will write the contents of the file to the iframe:

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

My problem here is that the iframe content is being rendered different on ie9 and ie11.

IE11:

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

IE9:

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

Any thoughts to make the iframe same as on IE11?

EDIT

I have the following code on my _Layout.cshtml :

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

Try adding a meta tag for IE:

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

It forces the browser the render at whatever the most recent version's standards are. Just like using the latest version of jQuery on Google's CDN, this is the most recent, but also can potentially break your code since its not a fixed version.

or you could be more specific with IE9 :

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

or

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

Checkout a detailed answer from here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM