Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Removes right-click on images
* This script will look for all images on a page and prevent right clicking on an image.
const images = document.getElementsByTagName('img');
for(var i = 0; i < images.length; i++) {
images[i].addEventListener('contextmenu', event => event.preventDefault());
// Note: I threw this script together as requested by a subscriber. I personally don't recommend doing
// this in a project because it is just annoying for users. With great power comes great responsibility.
// Just because you CAN do something, doesn't mean you SHOULD. But this is how you would do it if
// you felt it was necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment