3

i have a form thats inside a iframe with a input type file with an onchange event that submits the form whenever the input is modified, then i get a error in IE only works in other browsers.

e.g. (simplified version)

<form id="form1">
<input type="file" id="_file" onchange="document.forms[0].submit();$('#form1').hide()" />
<input type="button" onclick="$('#_file').click();" />
</form>

then IE 8 gives this error:

SCRIPT5: Access is denied.

I beleive it as to do with the fact that IE thinks its a security risk to submit from a event that wasn't fired by a user or it may have to do with the fact that it happens in an iframe. Any ideas on how to get around this ?

EDIT

It looks like the problem may have to do with the fact that the input[type:file] is hidden, well its got a small width and opacity:0 . after making it show and putting a submit button there it works , but i need it to work without the input[type:file] showing and without a submit button. However tried it with the input[type:file] showing and submiting in the onchange still doesn't work.

John
  • 3,512
  • 2
  • 36
  • 53
  • Here is a post that should help - http://stackoverflow.com/questions/1886547/access-is-denied-javascript-error-when-trying-to-access-the-document-object-of – Jay Blanchard May 07 '12 at 12:46
  • I don't see the relevance to my issue, I'm not creating the Iframe dynamicly. – John May 07 '12 at 13:00
  • You are getting the same error regardless of the creation of the iFrame. What is the document.domain of your iFrame? Does it match the parent document? – Jay Blanchard May 07 '12 at 13:06
  • at the moment it is "localhost" (while in the onchange event) the page the iframe is on also says "localhost" so doesn't look like the domains are different. – John May 07 '12 at 13:13

1 Answers1

4

Seems the problem is IE doesn't like it when you programtically set and submit file inputs. Found now way around this so giving up. I'm opting for using Jquery uploadify as a fallback when user is in IE. This puts an unwanted dependency on flash but thats the best alternative i can come up with.

John
  • 3,512
  • 2
  • 36
  • 53