How to capture the user select text event in Firefox
I want to catch the event when the user select a text in Firefox page like IDM add-on (or IE8+) show a button when user select text.
Can anyone help m开发者_如何学Ce?
You could attach a mouseup
event listener and a keypress
listener respectively for mouse and keyboard selections, and then use window.getSelection()
to tell if any text is selected.
Somewhat surprisingly, there's no simple way to do this. IE has a select
event that is implemented on all elements but other browsers have never extended this beyond inputs. You'll have to handle keyup
and mouseup
events for the whole document, and write some code to compare the current selection with the previous selection from when the event handler last ran.
精彩评论