Either by double click or move the mouse.
Anyone knows about this?
Either by double click or move the mouse.
Anyone knows about this?
I think that you refer to the select
event. See here: http://www.comptechdoc.org/independent/web/cgi/javamanual/javaevents.html
It's possible to use "onselect", but it works just for form elements (inputs, selects...).
function on_select() {
alert( "selected" );
}
...
<input name="input" onselect="on_select()">
Maybe you can bind a function to document.onmouseup
to call document.getSelection()
? This is assuming your users use mouse to select the text ;)
document.onmouseup = function() {
var sel = document.getSelection();
if (sel.length > 0) {
alert(sel);
}
}
In IE only the select
event applies to body text as well as form inputs, so would do what you want. IE and WebKit have selectstart
which fires when the users starts selecting, which probably won't help you. To detect when the user has made a selection in a cross-browser way you will need to handle both keyup
and mouseup
events. Even then you won't be detecting selection events such as the user using the "Select all" menu option (usually found in the Edit and right click context menus). The situation is not ideal in current browsers.