Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript ondrop event

Tags:

javascript

I'm using the drop event in JavaScript to upload files using the following code:

var fileName = event.dataTransfer.files[0].name;            
var orgValue = document.getElementById('<%=tbfilesCollections.ClientID%>').value;
if (orgValue == 'undefined') {
    orgValue = '';
}
orgValue += orgValue == '' ? '' : '\n';
orgValue += "*" + fileName;
document.getElementById('<%=tbfilesCollections.ClientID%>').value = orgValue;
event.preventDefault();
return false;

But this code only gets the file name... I need to get the full path of the file.

like image 938
Raed Alsaleh Avatar asked Dec 19 '12 08:12

Raed Alsaleh


People also ask

What is the functionality of Ondragover () event?

The ondragover event occurs when a draggable element or text selection is being dragged over a valid drop target. By default, data/elements cannot be dropped in other elements. To allow a drop, we must prevent the default handling of the element. This is done by calling the event.

What is drag event in JavaScript?

The DragEvent interface is a DOM event that represents a drag and drop interaction. The user initiates a drag by placing a pointer device (such as a mouse) on the touch surface and then dragging the pointer to a new location (such as another DOM element).


1 Answers

As this post points out, you cannot get the full path as you would like: Javascript File Drop.

As mentioned in the comments by Michael Sandino, there is a way to do this in Firefox with the "mozFullPath" attribute, but I have yet to see a universally-implemented way of accomplishing this.

The reason for this I would imagine is that the browser shouldn't divulge information regarding the folder structure of a client computer to a web application, which is understandable.

like image 91
Levi Botelho Avatar answered Oct 05 '22 14:10

Levi Botelho