0

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" />
Gerald Gonzales
  • 533
  • 2
  • 6
  • 20

1 Answers1

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.

Community
  • 1
  • 1
Jai
  • 74,255
  • 12
  • 74
  • 103
  • Thank you for the answer. I updated my question, unfortunately I already have this meta code on my `_Layout.cshtml` – Gerald Gonzales Nov 24 '15 at 09:36
  • is it the file which is loaded in the iframe? – Jai Nov 24 '15 at 09:37
  • My iframe is located on a file, say for example `File.cshtml`. This file is being rendered on the `_Layout.cshtml` by using the `RenderBody()` so I think it should be okay? – Gerald Gonzales Nov 24 '15 at 09:40
  • 1
    I did some research, turns out that I also need to specify the meta tag on the view even though it is already present on the `_Layout.cshtml`. Thank you for the idea! – Gerald Gonzales Nov 24 '15 at 09:47