.click() on <input type=“file” /> does not work in Firefox 3.6 - Any workarounds?

独自空忆成欢 提交于 2020-01-23 13:30:11

问题


Here is a little example: (live demo here)

HTML:

<input id="file" type="file" />

Javascript:

$(function() {
    $("#file").click();
});

In Firefox 3.6.6 nothing happens, while in IE7 the "Choose File" dialog box is opened.

Any ideas how to open the "Choose File" dialog box in Firefox without clicking on the Browse button ?


回答1:


The file-dialog breaks out of the sandbox your javascript code runs in (access to HDD). Good/secure browsers (= not IE7) should prevent that this dialog is opened via a script - it MUST be opened by a real mouseclick.

Some browsers seem to allow it, but it varies.

See more in In JavaScript can I make a “click” event fire programmatically for a file input element?




回答2:


this is fixed in Firefox Version 3.6.23



来源:https://stackoverflow.com/questions/3228284/click-on-input-type-file-does-not-work-in-firefox-3-6-any-workarounds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!