使用键盘快捷键将文件上传到HTML5页面 [英] Upload file to HTML5 page using keyboard shortcuts

查看:337
本文介绍了使用键盘快捷键将文件上传到HTML5页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以使用HTML5 File API拖放来上传文件。是否可以通过从文件资源管理器复制文件并使用CTRL-V / CMD-V将其粘贴到网页中或通过右键单击上下文菜单粘贴来完成此操作?

I know that it is possible to upload files using drag and drop with the HTML5 File API. Can this also be done by copying a file from the file explorer and paste it into a web page using CTRL-V/CMD-V or by pasting from the right click context menu?

推荐答案

你不能这样做。

你可以通过这个轻松获得文件路径:

You can get the file path easily with this :

$(document).on('paste',function(e){
    var path = e.originalEvent.clipboardData.getData("text");
});​

因此您可以向用户显示。

So you may show it to the user.

但你无法改变< input type = file> 的价值。

这是一个安全措施:想象一下,如果您的脚本可以在用户提交表单之前更改要上载的文件的路径(或者甚至没有用户交互,现在可以使用其他形式元素)?至于每个重要的安全保护,现代浏览器都没有已知的解决方法。

That's a security measure : imagine if your script could change the path of the file to be uploaded just before the user submits the form (or even without user interaction as is now possible with other form elements) ? As for every important security protection, there is no known "workaround" for modern browsers.

这篇关于使用键盘快捷键将文件上传到HTML5页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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