简体   繁体   中英

OpenFile dialog not working in IE8 using jquery or JavaScript?

I'm using an image (and input "file"-->hidden) when user clicks the image it's execute the following code:

$('#edtFile1').click(); //edtFile1 is the input for file choose...

It's working in FF, chrome and IE>8, in IE8 it's not working, I bind the click to image using jQuery 1.9 with this code:

//bind click on image-->file browse      
$("#btnimg1").click(function(event) {
    $('#edtFile1').click();
});

IE does not allow the file upload control trigger operation like you did.Instead of you can do like as below.Set File Upload control opacity to 0.

<div style="position:relative;display:inline-block;left:-4px;bottom:-6px;width:16px;  height: 24px;overflow:hidden;">
<img src="/images/attach.jpg" alt="" title="Add Attachment" style="height:24px;width:16px; position: relative;top: 1px; left: 0px;"/>
<input type="file" id="fileupload" name="upload" style=" opacity: 0;font-size: 50px;width:16px; filter:alpha(opacity: 0);  position: relative; top: -22px; left: -1px" />
</div>

For further reference, please see this. In JavaScript can I make a "click" event fire programmatically for a file input element?

Demo: http://jsfiddle.net/k6zBQ/2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM