Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript - click() doesn`t work in chrome

I have tried this, (note that I am using jQuery):

function HandleFileButtonClick()
{
    1. //$('#filesel').click();
    2. //document.replyform.image.click();
}

HTML:

<input type="file" id="filesel" name="image" style="display: none;"  /> 
<a href="#"><img src="<?=TF?>/img/att.png" style="height:20px;" onclick="HandleFileButtonClick();" /></a>

neither are working in Google Chrome Browser... any ideas, or a replacement for jQuery click()

like image 729
Andrei Stanca Avatar asked Nov 02 '25 16:11

Andrei Stanca


2 Answers

I am here to help other with a similar problem. I try use .trigger('click') to start a click event into a FILE field that was if style='display:none' and discovered that Chrome diferent from Mozila Firefox and IE don´t let it work with this style. The solution is don´t use display:none and use instead of it style='width:0px;height:0px'. The result is the same, the FILE field be hidden and you can use another button to start its works even in Chrome this time.

Best Regards peeps.

like image 146
Tiago Avatar answered Nov 05 '25 07:11

Tiago


Sounds like you are hitting a security wall designed to only allow the file upload box to be triggered by the user.

You could try absolutely positioning the browser's browse button over your link, and then setting its opacity to 0.

like image 26
alex Avatar answered Nov 05 '25 06:11

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!