javascript 浏览器支持拖放文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4259000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Browser support of drag and drop file uploads
提问by Oscar Godson
I can't seem to find it online anywhere, just demos or links to the spec, or the Google Gears implementation. That's all great, but I was curious what the actual browser support of it is across the main browsers AND OS. Firefox, Chrome, Safari, Opera, and does IE have an alternative? What about IE9?
我似乎无法在任何地方在线找到它,只有演示或规范链接或 Google Gears 实现。这一切都很棒,但我很好奇它在主要浏览器和操作系统上的实际浏览器支持是什么。Firefox、Chrome、Safari、Opera 和 IE 有替代品吗?IE9呢?
采纳答案by Oscar Godson
Firefox 3.5+ has a nice drag-and-drop api: https://developer.mozilla.org/En/DragDrop/Drag_and_Drop
Firefox 3.5+ 有一个不错的拖放 api:https: //developer.mozilla.org/En/DragDrop/Drag_and_Drop
Chrome you can can drag and drop onto a file upload, so, you can do drag and drop, but you have to fake it by hiding the form via opacity:0 but make it large via a wrapping div and a width:100% and height:100%: http://www.thecssninja.com/javascript/gmail-upload
Chrome,您可以拖放到文件上传上,因此,您可以进行拖放操作,但是您必须通过 opacity:0 隐藏表单来伪造它,但通过包装 div 和宽度使其变大:100% 和高度:100%:http: //www.thecssninja.com/javascript/gmail-upload
Safari is the same as Chrome except you can only do one file at a time, more on this at the link above at the end of the post (thecssninja link)
Safari 与 Chrome 相同,但一次只能处理一个文件,更多信息请参见文章末尾的链接(thecssninja 链接)
IE it seems like you can use VBDataObject or ActiveX, but i'm still not quite sure where to find more information. I can just find little snippets of information about how you could use those: http://www.codingforums.com/showthread.php?t=36896-- If anyone can help me with how to get IE to support it, let me know.
IE 似乎您可以使用 VBDataObject 或 ActiveX,但我仍然不太确定在哪里可以找到更多信息。我只能找到有关如何使用这些信息的小片段:http: //www.codingforums.com/showthread.php?t=36896-- 如果有人可以帮助我如何让 IE 支持它,请让我知道。
Opera has nothing at all it seems. Just playing with it, it acts like IE where if you drag onto a file upload it just opens that file. If anyone knows away around this let me know.
Opera 似乎什么都没有。只是玩它,它的行为就像 IE,如果你拖到一个文件上传它只是打开那个文件。如果有人知道这件事,请告诉我。
回答by Sanghyun Lee
To support HTML5 drag and drop file upload, the browser should support the drag and drop(DnD) API and the File API simultaneously.
要支持 HTML5 拖放文件上传,浏览器应同时支持拖放(DnD)API 和文件 API。
IE supports the DnD from IE5 but it doesn't support the File API even in IE9. Opera supports the File API from 11.1 but doesn't support the DnD.
IE 支持来自 IE5 的 DnD,但它甚至在 IE9 中也不支持文件 API。Opera 从 11.1 开始支持 File API,但不支持 DnD。
So you can use drag and drop file upload in Firefox 3.6+, Safari 6.0+, Chrome 9.0+.
因此您可以在 Firefox 3.6+、Safari 6.0+、Chrome 9.0+ 中使用拖放文件上传。
Check this compatibility table.
检查此兼容性表。
DnD http://caniuse.com/#search=drag
DnD http://caniuse.com/#search=drag
File API http://caniuse.com/#search=fileapi
回答by Pekka
回答by Richard York
Safari 5 does indeed support drag and drop of multiple files from the desktop to the browser. I've been using this feature for a good long time now, and I'm happy to share my code if you like.
Safari 5 确实支持将多个文件从桌面拖放到浏览器。我已经使用这个功能很长时间了,如果你愿意,我很乐意分享我的代码。

