Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form submit - IE access denied - same domain

SCRIPT5: Access denied 
jquery.min.js, line 3 char 3769

I'm getting this error by simple form submit only in IE

 $("#icon_upl").click(function(){ //icon_upl is button which open dialog
  $("[name=icon]").click();
});


$("[name=icon]").change(function() { //icon is hidden file input
  $("[name=upload_icon]").submit();  
});

I sending that form to hidden iframe which is at the same domain.

<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;display:none;"></iframe>
<form name="upload_icon" action="upload_icon.php" method="post" enctype="multipart/form-data" target="upload_target">

submit input doesn't help

I dont get it cuz if i try to send another form that works fine

like image 551
Lukasik Avatar asked May 19 '12 18:05

Lukasik


2 Answers

If you are triggering the select files dialog via JS then you will get an access denied error when submitting the form. IE does not allow this. You will have to ask user to click on input type file directly

More details here https://github.com/valums/file-uploader/issues/118#issuecomment-1387612

You can try styling the input type file though http://www.quirksmode.org/dom/inputfile.html

like image 73
apoorvi Avatar answered Oct 20 '22 20:10

apoorvi


I had similar HTML and jQuery code and encountered the same issue (i.e. 'Access is denied.' JavaScript error in Internet Explorer), which I managed to resolve by taking pointers from this (great) answer.

In your instance:

  1. Change the #icon_upl <button>/<input> to a <label> and make use of the tag's accessibility features by setting the for attribute on it to point to your <input name="icon" type="file"> element.

    This effectively makes your click() event handler redundant. However, clicking the <label> in Firefox does not seem to trigger the file <input> dialog so you'll need to perform a browser test and still have the click() event handler if the browser is Mozilla-based.

  2. In order for it to work, you'll need to make sure that your file <input> is not hidden by setting its position to be absolute and moving it off-screen.

like image 28
WynandB Avatar answered Oct 20 '22 20:10

WynandB