Jump to content

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

Recommended Posts

  • Replies 2
  • Views 1.4k
  • Created
  • Last Reply

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>

 

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

Archived

This topic is now archived and is closed to further replies.


×
×
  • 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.