What's The Event Fired When User Selects Some Text On The Page?
Solution 1:
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);
}
}
Solution 2:
I think that you refer to the select
event. See here: http://www.comptechdoc.org/independent/web/cgi/javamanual/javaevents.html
Solution 3:
Solution 4:
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()">
Solution 5:
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.
Post a Comment for "What's The Event Fired When User Selects Some Text On The Page?"