The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Drag and Drop

Hi,
I am trying to figure out how to enable the dragging and dropping of files into the browser window for a document management system. But everytime I try to catch the event supposedly fired the document dragged into the window simply loads up.

I.E
window.ondragdrop=myFunction;

I have read through some of the JS reference docs on the netscape website they mention the enabling of UniversalBrowserRead privalege to be able to read the data parameter of the event, but make no mention to how to catch the event.

Ive probably stopped making sense, but to recap I want to be able to get information such as the URL of a document that has been dragged into a region of a page. Currently IE just loads the document into the current window, I have tried capturing the dragdrop event and failed. Is there any way that I can make this work? Examples?

I experimented with it a little. When dragging a file from Explorer and dropping it on the browser, I can stop the browser from loading the file but 'getData()' doesn't return any information about the file. I think it has to do with security settings (reference).

Hi thanks for the reply,
I have looked through the MS stuff, and it appears that you need to set the data using setData before you can use getData to retrieve it. Which seems a little odd, but in the context of all there examples it seems to relate to moving objects inside the browser window and not outside in.

You can select text, drag and drop it, and the drop event fires and the selected text is available from getData(). You only call setData() (from the source element) if you want to customize the data that is dragged. By default it will be the selected text.

You can select text from a different browser window, drag and drop it on the original window, and the drop event fires and the selected text is available from getData().

When you drag a file from Explorer and drop it on the browser, the drop event does fire - but getData() returns null.

The docs at MSDN explain that even COM is supported by the dataTransfer object. But they also explain that the operation will fail if the two apps have different security models. If there is a solution, I think it will involve looking into this security issue.

Yeh I did try your code, and have read into the drag drop model from I.E. I will look into the security model, but whats the likelyhood of me being able to do this? Have you seen it anywhere before? Or am I going to have to create an ActiveX control (or something similar)?