IE doesn't allow to upload the file, if it is not keybord click for input type=file

十年热恋 提交于 2020-01-05 05:46:05

问题


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">

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/12556988/ie-doesnt-allow-to-upload-the-file-if-it-is-not-keybord-click-for-input-type-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!