Jump to content

Inject code for blocking right click and drag and save for images

Recommended Posts

I just found this guide by @tuanphan in a different post: https://beaverhero.com/squarespace-disable-right-click/. I used his header script injection to disable right clicks, but I specifically targeted images:

<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;
  });
});
</script>

 

Edited by Inscape
solved a problem mentioned in original post
Link to comment

Actually sorry, here is a better solution I found by combining @tuanphan's solution with another post, to disable both right clicking AND drag and save:

<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>

Again, this is for images ONLY. It seemed like a better option especially since I inspect elements and copy links so much using right click.

If it's not clear, this should go in Settings-->Advanced-->Code Injection-->Header.

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.