获取在字段上拖放的资源的 URL

Get URL of resource that is drag-and-dropped on field(获取在字段上拖放的资源的 URL)
本文介绍了获取在字段上拖放的资源的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个带有特定输入字段的 html 页面,我想添加以下功能.

I have an html page with a certain input field and I want to add the following functionality.

用户应该能够将资源拖放到字段上.这个动作的结果应该是资源的url出现在了字段中.

The user should be able to drag and drop a resource onto the field. The result of this action should be that the url of the resource appears in the field.

资源可以是一个本地文件,生成一个类似 file:///home/me/documentfile://c:windows-filesdocument 的 url.文档.

The resource could be a local file, resulting in a url like file:///home/me/document or file://c:windows-filesdocument.doc.

该资源也可以是一个网络资源,产生一个像 http://host.nl/document.doc 甚至 ftp://host.nl/document 这样的 url.doc,尽管此时我对 ftp 资源并不感兴趣.我假设来自网络浏览器的地址栏中的网页 url 的 dnd 操作,或者来自例如客户端计算机上的文件的 dnd 操作.桌面.

The resource could also be a web resource, resulting in a url like http://host.nl/document.doc or even ftp://host.nl/document.doc, although at this point I'm not really interested in ftp resources. I'm assuming a dnd-action of a web-page url from the address bar of a web browser, or a dnd-action of a file on the client machine from e.g. the desktop.

与 Web 应用程序一样,我希望此功能可以在大多数平台上运行.(Linux/Win/MacOS, Firefox/Chrome/Safari/IE/Opera)

As usual for web apps, I want this functionality to work on most platforms. (Linux/Win/MacOS, Firefox/Chrome/Safari/IE/Opera)

范例是 html 和 JavaScript.

The paradigm is html and JavaScript.

推荐答案

在 Firefox 中你可以使用 file.mozFullPath.但是,此变量仅在 Firefox 中出现,在 Chrome 或 Safari 中不起作用.

In Firefox you can use file.mozFullPath. However, this variable presents only in Firefox and don't work in Chrome or Safari.

这篇关于获取在字段上拖放的资源的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)