我想从我们的Windows文件服务器中拖出一个文件并将其放到网页中的文本区域
结果链接类似于:
<a href="\\fileserver\folder\pizza_2.pdf">filename.pdf</a>
答案 0 :(得分:1)
我认为以下代码可以帮助您:
<div id="drop_zone">Drop files here</div>
<output id="list"></output>
<script>
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
//** you gotta change these lines accordingly **
//output.push('<li><strong>', f.name, '</strong> (', f.type || 'n/a', ') - ',
// f.size, ' bytes, last modified: ',
// f.lastModifiedDate.toLocaleDateString(), '</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
}
// Setup the dnd listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
</script>
参考:http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-selecting-files-dnd