在Chrome中以编程方式打开上传文件对话框 [英] Programmatically open upload file dialog in Chrome

查看:157
本文介绍了在Chrome中以编程方式打开上传文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有输入[type = file] ,它上面有登录表单。所以在用户登录之后 - 立即打开文件上传对话框。



除了谷歌浏览器之外,我需要的所有浏览器(FF,IE10 +),这个调用都很完美:

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

  $( '输入[类型=文件]')[0]。点击(); 

  $( '输入[类型=文件]')触发( '点击'); 

有没有人遇到过这个问题?如果是这样,如何在Chrome上实现这一目标?



编辑1:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.click 在这里支持据说我可以在输入[type = file]上使用它。
此点击正在工作,但只有当我实际点击某些内容时,才会点击我的输入内容(因此只能在物理点击之后)。



编辑2 :
是的,我已经尝试过搜索功能。但是我发现的一切都很古老,几乎所有人都告诉我,即使FF也不支持这一点(现在不是这样)。

Edit3:
示例测试页面: http://jsfiddle.net/Ux3t4/

解决方案

由于安全原因,这是不允许的。顺便说一句,即使在Internet Explorer中(对话框将显示,但一旦你选择一个文件,该文件将不会被提交)。


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).

这篇关于在Chrome中以编程方式打开上传文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆