faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 7 people (29%) answered Yes
Recently 2 of 7 people (29%) answered Yes


How do I prevent dragging and dropping of files in IE?

Apr 5th, 2008 20:13
ha mo, Colin Fraser, Vijaya Meyyappan,

I am somewhat surprised at the length of time this question has remained
unanswered, and it is probably too late to reply to it now, but someone
else may benefit from this. So I am going to have a go at it and at
least open the debate on it, if anyone is interested. 
My starting assumption needs be that the user is going to try and click
within the document itself. Therefore, the simplest and easiest way to
deal with this is to use the browser's features to prevent it from
actually doing anything you do not want it to do.
Microsoft have always claimed that IE is more flexible and more user
friendly than any other browser and so on, etc. etc. ad infinitum, ad
nauseam. What they have failed to recognise is that a lot of people find
these "user friendly features" more of an annoyance than anything else.
Drag and drop is not necessarily one of those things, but the answer to
this question is obvious.  
<body onMousedown="Dothis(oname,doing)">
All that has been done here is to trap the mouse button as it has been
clicked, and a function that does something is called. 
Of course, the real problem is that this does not allow the user to do
anything with the mouse, so the Dothis() function needs to be something
pretty good to accomodate all sorts of clicks, ranging from submit
buttons to links. 
The function then needs to look something like 
Dothis(oname) {
switch (oname) {
case button1; 
case link1 
case image1
      alert("You must click on something like a link and image or a button")
All this depends on the user clicking inside the document. 
Anything else is way outside javascript's capabilities, as javascript
does not work outside the window object. If that is the case, look at
PHP or Java to provide a solution, which will, I suspect, end up looking
something similar to what is here.