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...