Jump to content

Disable right-click of images using only CSS

Recommended Posts

Site URL: http://dustin.land

Hello all! I just wanted to know if it is at all possible to disable right-click / dragging of images usingly only CSS. Sadly I cant code inject as it is in not in my plan.

If anyone knows of a way via css only without code injection, that would be great!

Link to comment
On 12/1/2021 at 2:13 PM, DustinWilliam said:

Site URL: http://dustin.land

Hello all! I just wanted to know if it is at all possible to disable right-click / dragging of images usingly only CSS. Sadly I cant code inject as it is in not in my plan.

If anyone knows of a way via css only without code injection, that would be great!

Hi @DustinWilliam,

Your final purpose is not allowing right click on image to save as it, isn't it?

image.thumb.png.719d3edc11b76d4a4fd279e1778e29e0.png

This is the current state when we right click on image.

If it is your point, i can give some code that only allow user to save the whole page, not the individual image

image.thumb.png.80cd43c8738211e37d98edbc1f21f49b.png

This is my idea that user can not save the image

Hope that it makes sense

Edited by bangank36

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

I've actually found a solution: CSS only:

img {
    pointer-events: none;
  -webkit-touch-callout: none;
}

when you right-click any image and save-as, an html file will be saved, no image file. 

Link to comment
  • 1 month later...

Hi,

I used Dustin's code on my website, it worked really well to prevent people to save your images, but it has an issue on mobile with 7.0 Forte indexes: it disable arrow's clicking on carousel indexes (both right and left arrow). Do anyone have another solution to disable right click ONLY on images whitout creating any issue on mobile?

Thank you.

Link to comment
23 hours ago, g_franchini said:

Hi,

I used Dustin's code on my website, it worked really well to prevent people to save your images, but it has an issue on mobile with 7.0 Forte indexes: it disable arrow's clicking on carousel indexes (both right and left arrow). Do anyone have another solution to disable right click ONLY on images whitout creating any issue on mobile?

Thank you.

Use this new CSS

@media screen and (min-width:901px) {
img {
    pointer-events: none;
  -webkit-touch-callout: none;
}
}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
1 hour ago, tuanphan said:

Use this new CSS

@media screen and (min-width:901px) {
img {
    pointer-events: none;
  -webkit-touch-callout: none;
}
}

 

Thanks Tuan,

in the meantime I made a mix of codes found in different places and modified for my needing (because I'm scary that your last modification could anyway cause trouble with arrow clicking on biggest tablet, but I don't know if I'm saying something wrong because I don't have a tablet to verify it).

 

I used this code to block from saving images on mobile:

Quote

img {

   -webkit-touch-callout:none;

}

I found the original version of that here: https://forum.squarespace.com/topic/9449-how-can-i-override-the-browsers-right-click-settings/#comment-266794 but it has the problem that it prevents to open links (or anything else) in other panels, copying text etc.

 

While to block right click image saving on desktop devices, I used this in Advanced > Code injection > Header, that you originally posted on your website https://beaverhero.com/squarespace-disable-right-click/ and was implemented to avoid image drag as well here: https://forum.squarespace.com/topic/203953-inject-code-for-blocking-right-click-and-drag-and-save-for-images/#comment-493592 

Quote

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function () {

  $("img").on("contextmenu",function(e){

    return false;

  });

  $("img").on("dragstart",function(e){

    return false;

  });

});

</script>

 

 

 

In this way I have the first code that avoid right click on mobile (only on images) and the second one that avoid from dragging and saving images on desktop.

 

If there is something missing or wrong that you can see, please tell me.

 

Edited by g_franchini
Link to comment
  • 1 year later...

Is there any way to lock down a site so that right clicking on a desktop or touch & hold on a mobile does not result in any kind of context menu? Certainly one that includes the saving of images, the opening of images in another tab or the inspection of elements?

My main specific issue is that I'm using an image slider from Rebecca Grace Designs to show before & after images. It's a fantastic bit of code & does exactly what I want but it's currently allowing me to save out the full quality master images from my site.

I'd like to know if this menu can be disabled without affecting the functionality of the slider?

Link to comment
  • 2 weeks later...

Hi All,

I'm completely new to this CSS code thing and am trying to prevent photos being downloaded from my website. I've figured out how to prevent right-click downloading, but I'm still not clear on preventing it on phones. This "New CSS" given above, where does it go in the code? In the SEO Header or Footer? Or elsewhere in the code found within the Themes. Thanks!

This is the code I'm referring to:

@media screen and (min-width:901px) {
img {
    pointer-events: none;
  -webkit-touch-callout: none;
}
}
Link to comment
4 hours ago, HeatherV said:

This "New CSS" given above, where does it go in the code? In the SEO Header or Footer? Or elsewhere in the code found within the Themes. Thanks!

This is the code I'm referring to:

@media screen and (min-width:901px) {
img {
    pointer-events: none;
  -webkit-touch-callout: none;
}
}

Hi, CSS goes in Custom CSS. You can find it here: Website -> scroll all the way down to Website Tools -> Custom CSS.

-------- > 👆 <---------- Please quote or @ me when replying, or I won't get a notification 

Melody | Squarespace Website Developer
e: melody@melodylee.tech


💻 Can't figure something out and want to learn? 💁‍♀️ 1-2-1 Squarespace session 
👩‍💻 Need some customisation for a design? 💁‍♀️ Custom Code help
 Did I help? 💁‍♀️ I like coffee

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.