views:

166

answers:

2

Is there a way to override the "undo" and "select all" in right click context menu of the browser over textarea?

Thank you.

+1  A: 

I know you can prevent the whole context menu from opening by registering to the click() event, doing some cross-browser mumbo-jumbo to get wich button was clicked, and then return false if the right one was clicked.

However, I don't think it's possible to modify the context menu itself, at least not using javascript.

I should add that you may want to rethink why you're doing this. This will never be a protection against anything (some try to prevent copying images from their website), as it may simply be disabled by turning javascript off.

UPDATE: Ok, so you don't want to prevent users to do things, bug have them doing things your way. Then, I guess the best thing to do is :

  1. Provide users with a toolbar that allow them to do these things (and thus making them use your actions instead of the default one
  2. Map the usual keyboard shortcuts to your actions (Ctrl+A, Ctrl+Z, etc...)
  3. Replace the right click menu with your own.

You mentionned in another comment that you cannot reproduce copy/paste, which is correct, but you can implement you own clipboard (that will only work for your webapp) if you really have to.

Wookai
I'm not trying to prevent people from stealing stuff, come on.I need to either change or disable "undo" and "select all" because they might and probably will create a mess in my webapp.
thedp
As I said before, there is no way to simulate "copy" and "paste"... And I do want my users to copy/paste from/to my webapp.. :/
thedp
+1  A: 

You cannot edit the browser's built-in context menu, but you can disable it and replace it with your own using the oncontextmenu event on the window object. I would caution that this is often a bad idea. Users expect to find the built-in context menu and are often frustrated when it isn't there.

Annabelle
It's useless to create my own menu since I can't simulate "copy" and "paste", damn security :P
thedp