tqwer
tqwer

Reputation: 93

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 me?

Upvotes: 3

Views: 1485

Answers (2)

Ryan Li
Ryan Li

Reputation: 9330

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.

Upvotes: 3

Tim Down
Tim Down

Reputation: 324567

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.

Upvotes: 0

Related Questions