PDA

View Full Version : prevent default action: IE, mousedown


ondras
04-19-2007, 11:08 AM
Hi,

I am really stuck in solving the situation described in thread's title. I basically want to assign an event to element's 'mousedown' event, but I need to stop default action associated with such event.

I try:

function func(event) {
event.returnValue = false;
...do stuff here...
}
element.attachEvent("onmousedown",func);

This works for most event types, but not for 'mousedown'. In other words, the default action is always performed.

Reason for this: I need to implement drag&drop, but when I start dragging an image, a 'forbidden' cursor appears (as a result of default mousedown action).

Any help will be greatly appreciated.

Pepejeria
04-20-2007, 12:02 AM
You seem to be doing an IE solution only?

Glass Casket
04-20-2007, 12:14 AM
Not sure if this will help but:


// If the preventDefault is valid (everything but IE)
if(document.preventDefault)
e.preventDefault();
else
// IE
e.returnValue = false;

ondras
04-20-2007, 09:03 AM
Of course I am not doing an IE-only solution. This is the IE-specific part. I use a routine similar to the one above to distinguish between event models. However, this doesn't help me in any way in solving this issue.

mrhoo
04-21-2007, 06:51 AM
You may need to stop the event bubbling. In IE set event.cancelBubble=true.

ondras
04-21-2007, 09:35 PM
No. This does not solve my problem. (by the way, there is no single reason why stopping bubbling should cancel default action)

mrhoo
04-23-2007, 03:47 AM
there is no single reason why stopping bubbling should cancel default action

That is correct- canceling the event propagation prevents it from needing to be cancelled beyond the current source (target) element. I assumed you had cancelled the current default.