ios-lizard
ios-lizard

Reputation: 834

Programmatically trigger file browser in FineUploader

I'm using FineUploader and I'd love to be able to programmatically trigger the file browser. I imagine something like this:

uploader.fineUploader('browseFiles');

Unfortunately I couldn't find anything like that around the interwebs. Ideas?

EDIT

Tried the following as suggested but the file browser is not triggered :( The issue seems to be that this would call the click event handler defined by the developer (which, in my case, doesn't exist), not the one defined by FineUploader.

$('.qq-upload-button-selector').click();
$('.qq-upload-file-selector').click();
$('.qq-upload-filename-selector').click();
$('.qq-edit-filename-selector').click();
$('.qq-upload-file').click();
$('input[type="file"]').click();

Upvotes: 2

Views: 2167

Answers (3)

Cliff Liu
Cliff Liu

Reputation: 196

$('input[name="qqfile"]').click();

The input file control is initialized with default name "qqfile". You may look up the source code or inspect the input element by using the Chrome DevTool. It is simpler way to trigger the file window. The relevant source code are shown below by imaging. Initialize the options.

Create the element of input file.

Upvotes: 2

Danus
Danus

Reputation: 1

$('input[type="file"]').click();

works OK in my web with fine uploader (tested with IE, Chrome, and Firefox).

Upvotes: 0

Mark Feltner
Mark Feltner

Reputation: 2041

There is not a reliable, working, and cross-browser way to initiate the file browser dialog programmatically. A quick search around the internet for programmatically clicking an input element shows this is true:

Programmatically trigger "select file" dialog box

jQuery : simulating a click on a <input type="file" /> doesn't work in Firefox?

This is because programmatically opening the file browser would be extremely risky and open the door for malicious sites to trick users into uploading their data unknowingly.

Upvotes: 1

Related Questions