Skip to content

Instantly share code, notes, and snippets.

@jvilk
Created January 8, 2015 06:07
Show Gist options
  • Save jvilk/fa21b1df1b08064208e7 to your computer and use it in GitHub Desktop.
Save jvilk/fa21b1df1b08064208e7 to your computer and use it in GitHub Desktop.
Disable right click menu
/**
* Disables the right click menu for the given element.
*/
function disableRightClickContextMenu(element) {
element.addEventListener('contextmenu', function(e) {
if (e.button == 2) {
// Block right-click menu thru preventing default action.
e.preventDefault();
}
});
}
// Once the page is loaded, disable the right click menu of the canvas.
$(document).ready(function() {
disableRightClickContextMenu(document.getElementById('canvas'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment