Page 1 of 1
How To Stop Hyperlink Dragging And Text Selecting w/ jQuery
Posted: Wed Feb 04, 2009 1:30 am
by supermike
If you have jQuery, you can stop your hyperlink dragging and text selecting by doing this:
Code: Select all
$('A').each(function() {
$(this)
.css('MozUserSelect','none')
.bind('selectstart', function() {
return false;
})
.bind('draggesture', function() {
return false;
});
});
Note I've only tested in FF. You may need to make adjustments for IE.
Re: How To Stop Hyperlink Dragging And Text Selecting w/ jQuery
Posted: Wed Feb 04, 2009 1:58 pm
by kaszu
Thanks for sharing.
Only I can't imagine when it would be useful.
Re: How To Stop Hyperlink Dragging And Text Selecting w/ jQuery
Posted: Wed Feb 04, 2009 10:56 pm
by supermike
kaszu wrote:Thanks for sharing.
Only I can't imagine when it would be useful.
It's useful because it happens to me a lot in FF. Sometimes when I'm clicking something, I end up clicking and dragging by accident. It happens either with a stuck mouse, or a stuck touchpad, etc. What happens is that FF creates a "ghost-like" copy of the text I just clicked, makes it swing out wherever the cursor is, and then when I lift the mouse up, it swings back where it was. It's distracting and ugly. This is part of the browser's normal drag and drop features. I noticed in Gmail that they turned this off on some of the links. So, I set out to figure this out. With enough experimentation, I figured it out.
Re: How To Stop Hyperlink Dragging And Text Selecting w/ jQuery
Posted: Sun Feb 08, 2009 5:26 am
by Chris Corbyn
I'd be very careful about where this is used. Tricks like this often lead to usability nightmares since they interfere with often expected behaviour.
Re: How To Stop Hyperlink Dragging And Text Selecting w/ jQuery
Posted: Tue Feb 10, 2009 6:43 am
by gethinw
supermike wrote: I noticed in Gmail that they turned this off on some of the links. So, I set out to figure this out. With enough experimentation, I figured it out.
Gmail doesn't actually use this on links, just things which look like links (ie have a 'hand' cursor when you're hovering over them, but aren't 'a' tags).
If it annoys you, I'm sure there's some way to turn it off in firefox preferences (about:config in the address bar), but you shouldn't assume that your users don't like it - I find it's quite helpful if I'm trying to drag a link onto the bookmarks toolbar, for example.