views:

2687

answers:

2

Hello all. I'm working on a web application for which I'm attempting to implement a full featured windowing system. Right now it's going very well, I'm only running into one minor issue. Sometimes when I go to drag a part of my application (most often the corner div of my window, which is supposed to trigger a resize operation) the web browser gets clever and thinks I mean to drag and drop something. End result, my action gets put on hold while the browser does its drag and drop thing.

Is there an easy way to disable the browser's drag and drop? I'd ideally like to be able to turn it off while the user is clicking on certain elements, but re-enable it so that users can still use their browser's normal functionality on the contents of my windows. I'm using jQuery, and although I wasn't able to find it browsing the docs, if you know a pure jQuery solution it would be excellent.

In short: I need to disable browser text selection and drag-and-drop functions while my user has the mouse button down, and restore that functionality when the user releases the mouse.

Thanks for any advice, I've been searching for a while on this with no luck.

+3  A: 

Try preventing default on mousedown event:

<div onmousedown="event.preventDefault ? event.preventDefault() : event.returnValue = false">asd</div>

or

<div onmousedown="return false">asd</div>
Sergey Ilinsky
Works like a charm, thanks a bunch. ^_^
Nicholas Flynt
+1  A: 

Found this page that talk about both js and css solutions.

http://wiki.forum.nokia.com/index.php/How_to_disable_dragging_of_images_and_text_selection_in_web_pages

Thomas