問題描述
我有一個帶有特定輸入字段的 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/document
或 file://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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!