aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Stop text select on click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Stop text select on click" Watch "Stop text select on click" New topic
Author

Stop text select on click

Marc Luzietti
Ranch Hand

Joined: Feb 02, 2006
Posts: 84
Is there a way to stop the browser from selecting text when a user clicks on it? I have a JavaScript that opens or closes a menu you when you click on a list item. Frequently, however, when a user clicks on the "button" the text is selected instead, so the on click event is not triggered.

Any way around this?

Using anchor elements isn't an option because the sucky CMS we have loses its data when you use empty anchors, including simply hash marks and javascript declarations.


Support Kathy Sierra
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

The user must be doing a drag rather than a click to effect a selection. There's not much you can do about that.

Or is there more to the story?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marc Luzietti
Ranch Hand

Joined: Feb 02, 2006
Posts: 84
It's possible that minute mouse movements cause the problem, but I notice that if I double click on a word in a post, it is highlighted. Perhaps this is a windows problem. In testing just now, it occurs in all web enabled applications, but in a non-web enabled app it did not. I see it in both IE and FF, Dreamweaver, and Lotus Notes. I really only care about the browsers though. Also, if I triple click an entire line is selected.
[ March 05, 2007: Message edited by: Marc Luzietti ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Yes, that's the way things work. I guess you could try capturing the clicks and double clicks and timing them to cancel the event bubbling. But that all sounds like a lot of effort to go through for something no one else seems to have run into problems with. And I don't even know if it would work.
[ March 05, 2007: Message edited by: Bear Bibeault ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
http://codingforums.com/archive/index.php?t-62435.html

Eric
Marc Luzietti
Ranch Hand

Joined: Feb 02, 2006
Posts: 84
Thanks Eric.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stop text select on click