Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input File Click Chrome

Ok so I have an input element of type file and id "test"

When I put in the address bar: javascript: document.getElementById("test").click() it brings up the open file dialog so the user can decide what to upload. However if this same exact line is inserted into the document or done in the console of chrome it does not bring up the open file dialog. In fact the console says that the click() function is undefined. Is there any way in chrome to do this?

Cause it seem to work fine for any of the other browsers

like image 644
Anonymous Avatar asked Feb 02 '11 18:02

Anonymous


1 Answers

You should wrap file-input element to other (ex.:div): HTTM:

<div>
<input type='file'>
<div>

CSS:

div{
height:1px;
overflow: hidden;
}

JS:

$('div input').click();

Good luck...

like image 199
SparX Avatar answered Oct 04 '22 00:10

SparX