处理Firefox扩展中的文本选择事件(阻止用户选择文本) [英] Handling text selection event in Firefox extension (preventing user from selecting text)

查看:135
本文介绍了处理Firefox扩展中的文本选择事件(阻止用户选择文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否在chrome代码中,我们有更好的方法来检测用户选择/突出显示当前页面中的某些内容,而不是侦听 keyup / mouseup 并检查 window.getSelection()。任何想法?

编辑:其实,我想要做的只是防止用户在contentDocument中根本没有选择任何文本。完成这件事情也会很好。 (获取选择事件背后的想法是 preventDefault()或否则 getSelection()。removeAllRanges()



edit2:请注意,我不仅需要防止突出显示出来,而且还要防止发生选择。

edit3:我不需要阻止复制,而是选择元素。

 < script type =text / JavaScript的> 
document.body.style.MozUserSelect =none;
document.body.style.cursor =default;
< / script>

它不仅禁用高亮,还禁用选择本身。如果您尝试通过鼠标或箭头键选择一个区域(点击一个位置,并按下 SHIFT 时用箭头键导航),然后按 STRG + C ,没有任何反应。



变化后的唯一选择是 STRG + A < (code>& STRG + C copys all)。这可能是通过键盘事件来避免的。






编辑:我看到你的链接到 Mozilla文档中心,而他们写它只控制外观,我所有的测试火狐3.6显示它也影响选择,不仅外观。但它可能会在未来的版本中改变...


I was wondering if in chrome code we have some better way to detect when the user selects/highlights something in the current page than listening for keyup/mouseup and checking window.getSelection(). Any ideas?

edit: Actually, what I'm trying to do is simply preventing the user from selecting any text at all in the contentDocument. Something that accomplishes this will be fine as well. (The idea behind getting the selection event was just to preventDefault() or otherwise getSelection().removeAllRanges())

edit2: Please note that I need not just to prevent the highlighting from showing up, but rather the selection from happening.

edit3: I don't need to prevent copying but rather selecting the elements.

解决方案

If you put the following scipt in you body, selection will be disabled in Firefox:

<script type="text/javascript">
   document.body.style.MozUserSelect = "none";
   document.body.style.cursor = "default";
</script>

It does not only disable the highlight, it also disables the selection itself. If you try to select an area via mouse or by arrow-keys (clicking an position and navigating with arrow-keys while SHIFT is pressed) and and press STRG+C, nothing happens.

The only selection that works after that change is STRG+A (no selection visible, but STRG+A & STRG+C copys all). It might be possible to avoid that by keyboard-events.


Edit: I saw you comment with link to Mozilla Doc Center and while they write it controls only the appearance, all my tests in Firefox 3.6 show that it affects also the selection, not only the appearance. But it might be changed in future Releases...

这篇关于处理Firefox扩展中的文本选择事件(阻止用户选择文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆