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

2023-02-24前端开发问题
3

本文介绍了获取在字段上拖放的资源的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125