Dawn - Disable right-click on images only

Topic summary

A store owner using the Dawn theme wants to modify their site’s right-click protection to target only images, rather than disabling right-click functionality across the entire site.

Current situation:

  • Site-wide right-click is disabled via JavaScript in the global.js file
  • Owner wants visitors to retain right-click for actions like copy/paste and opening links in new windows

Proposed solution:

  • A code modification was suggested that checks if the clicked element is an image (using e.target.tagName === 'IMG') before preventing the context menu
  • This would restrict the right-click block to images only

Outstanding issue:

  • One user reports the suggested code still allows saving images on mobile devices
  • No solution has been provided yet for the mobile image-saving problem

Note: The conversation acknowledges this isn’t true protection against image downloading.

Summarized with AI on November 20. AI used: claude-sonnet-4-5-20250929.

My site: etherealoasis.co

My theme: Dawn

I currently have all right-clicking disabled on my site with the following javascript code in global.js file:

document.addEventListener('contextmenu', function(e) {
  e.preventDefault();
  alert('Right-click has been disabled on this site. Please contact info@etherealoasis.co if you need further assistance.');
});

I’d like to remove this and add code to disable right-clicking on images only, so that visitors can still right-click to copy/paste or to open links in a new window, etc., but to not be able to right-click on images.

Thanks in advance for any assistance!

Not that it’s a real protection, but you can modify your code like this:

document.addEventListener('contextmenu', function(e) {
  if( e.target.tagName === 'IMG' ) {
    e.preventDefault();
    alert('Right-click has been disabled on this site. Please contact info@etherealoasis.co if you need further assistance.');
  }
});
1 Like

Hello. I tried this but I am still able to save image while on a phone. How do you add code to fix that?