简体   繁体   中英

Programmatically open upload file dialog in Chrome

I have input[type=file] with log-in form on it. So after user logged in - file upload dialog instantly opened.

In all browsers I need (FF, IE10+) except Google Chrome, this call works perfect:

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

or

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

or

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

Did anyone met this problem? If so, how to achieve this on Chrome?

Edit1: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.click here in support it's said that I can use it on input[type=file]. Also this click is working, but only if I'll actually click something, that than is clicking my input(so only after physical click).

Edit2: And yes, I've already tried search function. But everything I've found was old, and pretty much anyone told, that even FF is not supporting this (which is not true now).

Edit3: Example test page: http://jsfiddle.net/Ux3t4/

This is not allowed due to security reasons. By the way, even in Internet Explorer (the dialog will be shown but once you select a file, the file won't be submitted).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM