thedp
thedp

Reputation: 8508

Browser Context Menu customization?

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

Thank you.

Upvotes: 1

Views: 2497

Answers (2)

Wookai
Wookai

Reputation: 21723

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.

Upvotes: 1

Annabelle
Annabelle

Reputation: 10716

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.

Upvotes: 1

Related Questions