开发者

How to capture the user select text event in Firefox

开发者 https://www.devze.com 2023-01-29 22:44 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消