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

Entry

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.  
Try:
<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; 
      submitform1()
      break;
case link1 
      document.location("http://www.another.site.com/index.htm")
      break;
case image1
      window.open("new,htm","....")
      break;
default
      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.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com