views:

227

answers:

3

I'm trying to make a calendar page where you can click and drag to select multiple calendar days at once. Everything works fine in Google Chrome, but in Firefox, when I try to start dragging, it fails. The reason for this is that each calendar day is contained in a link (<a></a>). When you try to drag links in Firefox, it does its own action. Is there any way I can prevent this or work around it?

A: 

If you're using jQuery, do the following. $( "a" ).click(function(){ return false; });

return false prevents the browser's defaults.

I'm using jQuery, but that didn't work. I tried Firefox's event.preventDefault(); as well.
John
A: 

For IE you can also add:

    // prevent text selection in IE
    document.onselectstart = function () { return false; };
    // prevent IE from trying to drag an element
    target.ondragstart = function() { return false; };
Wilq32
It works fine in IE. Sorry.
John
+1  A: 

I ran into this issue, saw your thread. In my case, I handling the lower level mouse events, not click. I found that on jQuery's mousedown (http://docs.jquery.com/Events/mousedown#fn) I could suppress Firefox's special behavior calling event.preventDefault (http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29) on the incoming mouse event.

I was calling it on other event handlers, but I suspect just mousedown() is sufficient to stop browsers from doing their custom drag behavior.

Frank Schwieterman
I thought I had tried that, but maybe I only tried event.preventDefault on click. Either way, I just changed the links to divs, and that solved my problems.
John