I have div which one on click trigger input-file. In other browsers (Chrome, Firefox, IE) it's working but in Safari(5.1.7) it doesn't. Any idea why?
$(function() {
$("#mask-button-file").click(function () {
$("#mask-load-file").trigger('click');
});
});
<div id="mask-button-file" class="hover active">
. . .
</div>
<input type="file" id="mask-load-file" name="file1" >
#mask-load-file{
display:none;
opacity:0;
}
#mask-button-file{
width:81px;
height: 40px;
background-color: #f70808;
float:left;
text-align: center;
vertical-align: middle;
line-height: 40px;
margin-left:1px;
cursor:pointer;
}
#mask-button-file:active{
background-color:#DF0005;
}
It's because the input is being set to display:none
and this has issue in safari.
Instead of hiding it, wrap it inside a div with height
, width
set to zero.
<div>
<input type="file" id="myfile" name="upload"/>
</div>
CSS:
div {
width: 0px;
height: 0px;
overflow: hidden;
}
Another option will be to position the input out of the viewport so that it's not visible.
You can refer this post: Jquery trigger file input for more options about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With