4

I am currently working on a new site under .NET MVC platform and I am trying to implement an asynchronous user upload image through iframe. Although I almost complete my task and is fully functional in any other browser fails in IE 9 with the follow error: Microsoft JScript runtime error: Access is denied. It looks like a security concern. Allow me to describe my issue using below code snippets with comments: 1. I have an html form with an input file that its visibility is hidden. Inside the form there are one input element with type="file" and a submit button (also hidden).

<div class="brandLogo">
<p>@identity._RetailerLogo.Caption</p>
<div id="LogoContainer" class="imgLogo">
    <img id ="CompanyLogo" src="@DefaultRetailerImage" alt="" title="@Model._ADD_LOGO_IMAGE">
</div>
<p class="txtR">
<a id="UploadLogo" href="#" style="position: absolute; left: -999em; top: -999em;">Upload
</a>
</p>

<form id="UploadForm"
    action="@Url.Action("editLogo", "Profile")"
    method="POST" enctype="multipart/form-data"
    name="UploadForm"
    target="UploadTarget"
    style="position: absolute; left: -999em; top: -999em;">
<input name="UploadLogoFile" id="UploadLogoFile" type="file" onchange="clickUploadButton();" />
<input type="button" id="SubmitLogoForm" value="Save Image" />
</form>

<iframe id="UploadTarget" onload="UploadImage_Complete();" name="UploadTarget" style="position: absolute;
left: -999em; top: -999em;"></iframe>

  1. The html form tries to post the file to an iframe via javascript. Both form and iframe are on my local project (asp.net mvc) under the same domain ( i run this under localhost).

  2. I am using an on change event on the input element to capture that user selected something and to trigger the submission of the form with ajax call. So when I call via javascript: $("#formID").submit() I get an access denied error.

Any help would be appreciated

tereško
  • 58,060
  • 25
  • 98
  • 150
user1649802
  • 41
  • 1
  • 2

1 Answers1

2

I saw this IE bug before,finally I changed my method .triggering change event of input element programmically consider as security risk by IE :( (so stupid IE)

By default IE not let you trigger file element change, if you want you this feature can use ajaxuploader or fileuploader

var uploader = new qq.FileUploader({
// pass the dom node (ex. $(selector)[0] for jQuery users)
element: document.getElementById('file-uploader'),
// path to server-side upload script
action: '/server/upload'
});
Yuseferi
  • 7,931
  • 11
  • 67
  • 103