Disable right click on images only

For personal privacy reasons I wanted to initially disable the right click menu for images on my website. Although it does next to nothing for preventing users to save my images to their computers, I implemented it anyway. Notice how there is also a check for session storage, to see if the user has clicked a certain button. This will be discussed in a later post extensively. This code uses Jquery library, because I had no idea what I was doing when I wrote it, copying most of it from the web.

HTML:

JAVASCRIPT:

const sacredButtonClicked = sessionStorage.getItem('sacredButtonClicked');
if (sacredButtonClicked === null || sacredButtonClicked === 'false') {
$(document).ready(function () {
  $("body").on("contextmenu", "img", function (e) {
    // Prevent context menu only for images
    return false;
  });
});
}
CSS:

Previous
Previous

Adding Stock search in shop (Redundant)

Next
Next

Interactive Ferrofluid separator