1

I have a requirement where i need to trigger the input[type=file] from another button and upload the files. This input[type=file] is a popup window for browsing the file which the user wants to upload. This window opens successfully but when uploading the file, it gives me SCRIPT5: Access is Denied error . I cannot replace the fake button with input[type=file], is there a way i can trigger click on input[type=file] even it is not from keyboard click and still upload the file. As per my research IE doesn't allow upload file unless we trigger input-type=file via keyboard click.

var uploadConfig ={
    init: function(){
        $('input#fileUpld_input').livequery("click",function() {
        });
    },
    open: function() {
        $('input#fileUpld_input').trigger('click');
    },
    upload: function(){
        $('.start').click();
    }

Browser

<input type="file" id="fileUpld_input" name="fileUpld_input" class="fileUpld">
2
  • 1
    I ran into a similar issue and my research led me to a security issue. IE intentionally blocks this as its a security risk. My solution was to use feature detection and only display the standard file input for IE, other browsers have a CSS styled button to open the file browse dialog in addition to drag & drop support. Commented Sep 23, 2012 at 23:00
  • @Mark I wish there is some jQuery script which can provide a workaround for this. Commented Sep 24, 2012 at 0:18

2 Answers 2

5

Use the code shown in the other answer worked for me: working JSFiddle

<input type="file" id="fileUpld_input" name="fileUpld_input" class="fileUpld">

I had the same problem, but determined that it was with IE not the code. After spending waaay too much time trying to sort out the error in my code; I fired up my laptop and could not replicate it. Eventually a reboot and restart of IE fixed the issue.

Sign up to request clarification or add additional context in comments.

1 Comment

browsing works but it will fail when you upload it. Have you checked uploading the file?
0

is there a way i can trigger click on input[type=file] even it is not from keyboard click.

try this: http://jsfiddle.net/RASG/FkdCm/

HTML

<input type="file" id="fileUpld_input" name="fileUpld_input" class="fileUpld">

<br>
<br>
<br>

<button id="theotherbutton">try me</button>

JS

$('#theotherbutton').click(function() { $('#fileUpld_input').click() })

Tested with IE 9 and FF 16

2 Comments

sorry downvoter, but my crystal ball is broken. i cannot guess what is wrong with my answer. could you explain? thanks.
@RASG it is not about the popup windows opens to choose file. That works fine to me either, but when you again click on upload button, it will fail with Access denay error. This only happens if the input-type=file wasn't triggered from keyboard click

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.