I would like to know when a user selects text in an html page using Javascript. The text should not be editable. The onselect
event seems to be only applicable to <textarea>
and <input type="TEXT">
tags. The event is not fired if either tag is disabled.
Is there a way around this with these tags?
Is there a completely different approach?
Sure, an example exists here: http://www.codetoad.com/javascript_get_selected_text.asp
Using what you see here, you could bind events to the click/release events of the document body, and check to see if there is a selection, and how long the selection is to determine if they've selected any text.
StackOverflow Archive: