Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input type="file" auto click

Tags:

javascript

How do I automatically open the browse dialog of an input type="file" when the page first opens?

like image 361
Phillip Senn Avatar asked May 04 '10 21:05

Phillip Senn


2 Answers

I don't think you should do this. If you've ever visited a MySpace page, you know how frustrating it can be when a web page activates things on its own when the page loads.

Don't violate how the UI is supposed to work, let the user ask for the dialog.

Besides, if the users instinctively closes it like a popup, and then realizes they needed it, it may not be obvious how they should get the dialog back. Then they will reload the page just to show the dialog again -- all frustrating things you could be avoiding.

That being said, I'm not sure why you want to do this in the first place. This is just my first reaction to what you're asking.

like image 186
Carson Myers Avatar answered Oct 04 '22 02:10

Carson Myers


This is completely impossible in Firefox.

In other browsers, you can:

document.getElementById('inputId').click();
like image 39
SLaks Avatar answered Oct 04 '22 02:10

SLaks