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?
views:
227answers:
3
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
2009-07-06 03:14:32
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
2009-07-06 08:02:59
+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
2009-08-15 02:06:58
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
2009-08-15 17:05:22