简体   繁体   English

如何在Firefox中捕获用户选择文本事件

[英]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. 我想在用户选择Firefox页面中的文本时捕获事件,如IDM附加组件(或IE8 +)在用户选择文本时显示按钮。

Can anyone help me? 谁能帮我?

您可以分别为鼠标和键盘选择附加mouseup事件侦听器和keypress侦听器,然后使用window.getSelection()来判断是否选择了任何文本。

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. IE有一个在所有元素上实现的select事件,但是其他浏览器从未将其扩展到输入之外。 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. 您将不得不处理整个文档的keyupmouseup事件,并编写一些代码来比较当前选择与上次运行事件处理程序时的先前选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM