[javascript] How to add a custom right-click menu to a webpage?

Answering your question - use contextmenu event, like below:

_x000D_
_x000D_
if (document.addEventListener) {_x000D_
  document.addEventListener('contextmenu', function(e) {_x000D_
    alert("You've tried to open context menu"); //here you draw your own menu_x000D_
    e.preventDefault();_x000D_
  }, false);_x000D_
} else {_x000D_
  document.attachEvent('oncontextmenu', function() {_x000D_
    alert("You've tried to open context menu");_x000D_
    window.event.returnValue = false;_x000D_
  });_x000D_
}
_x000D_
<body>_x000D_
  Lorem ipsum..._x000D_
</body>
_x000D_
_x000D_
_x000D_

But you should ask yourself, do you really want to overwrite default right-click behavior - it depends on application that you're developing.


JSFIDDLE

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to contextmenu

How to add a "open git-bash here..." context menu to the windows explorer? Android: How to enable/disable option menu item on button click? How to add a custom right-click menu to a webpage? Making custom right-click context menus for my web-app Right click to select a row in a Datagridview and show a menu to delete it right click context menu for datagridview How do I create a right click context menu in Java Swing? How to disable right-click context-menu in JavaScript

Examples related to right-click

Adding a right click menu to an item How to add a custom right-click menu to a webpage? Java Mouse Event Right Click Making custom right-click context menus for my web-app How to disable mouse right click on a web page? Right click to select a row in a Datagridview and show a menu to delete it right click context menu for datagridview How to distinguish between left and right mouse click with jQuery