Handling text selection event in Firefox extension (preventing user from selecting text)?

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

If you put the following scipt in you body, selection will be disabled in Firefox: 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...

In the absence of suitable events such as select and selectstart (which are indeed absent in Firefox, which has the select event but only applies it to form controls), all you can do is use mouse and keyboard events, as you suggested in the question. Preventing the default action of all mousedown events in the document is no good because it will prevent all interactive elements such as links and form elements from working. Instead, you could do something like the following that zaps a selection as it is made using the mouse and keyboard.It won't prevent selection via "Select All" in the context and edit menus though, since there is no way of detecting those at all in Firefox.

If you need to deal with this, polling the selection is your only hope. Function killSelection() { window.getSelection().removeAllRanges(); } document. AddEventListener("mousedown", function(evt) { document.

AddEventListener("mousemove", killSelection, false); }, false); document. AddEventListener("mouseup", function(evt) { document. RemoveEventListener("mousemove", killSelection, false); }, false); document.

AddEventListener("keydown", killSelection, false); window. AddEventListener("blur", function(evt) { document. RemoveEventListener("mousemove", killSelection, false); }, false).

You can use CSS to prevent the user selecting text. See my answer here: css rule to disable text selection highlighting To set this via JavaScript in Firefox, you can do the following: document.body.style. MozUserSelect = "-moz-none.

That disables only the appearance of text highlighting: ("Controls the appearance (only) of selection. This does not have any affect on actual selection operation. ").

I really need to disable it completely. – CAFxX Mar 6 at 16:32 @CAFxX: In which case you're back to checking key and mouse events (keydown and mousedown would be better than keyup and mouseup) in Firefox, which doesn't support the select or selectstart events for general selections. Even that isn't enough, since it's possible to alter the selection via other means, such as the "Select All" option in the Edit and context menus.

– Tim Down Mar 6 at 17:07.

The Copy command is enabled and disabled by an event. You can get notified of this event by creating a command updater.

I need to downright disable the ability to select elements, not disabling the copy command. – CAFxX Mar 12 at 15:46.

You can use css -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions