Squarespace - disable right click

disable right click on Squarespace

A bit unrelated to photography, but I was searching in vain for an easy way to prevent right-clicking on this site to discourage people from downloading images. I know there are plenty of easy ways to grab images, but I want to keep it to a minimum. Searching across various search engines and even the Squarespace site was tedious, but with a bit of help from AI, I was able to come up with a pretty cool solution to discourage right-clicking for those attempting to download images.

As a former senior-level network engineer, I still like to geek out every once in a while and puzzle through programming challenges. But this one is super simple—just wait for the surprise you’ll see in a second!

So you’ll need to navigate over to PAGES

Scroll to the bottom and choose WEBSITE TOOLS

Under Custom Code choose CODE INJECTION

In your header, paste the following code. You’ll notice I’ve also added some funny prompts that will randomize each time someone tries to right-click on my site. Mine are a bit cheesy, but I figured I’d have some fun entertaining those trying to grab my images. You can change them to however you like after pasting into Squarespace.

____________________________________________________________

<script>

document.addEventListener('contextmenu', function(event) {

event.preventDefault();

// Array of messages

var messages = [

"Ah, young grasshopper, you seek wisdom where none is offered. Some secrets must remain hidden until the time is right.",

"Whoa there, Sherlock! No behind-the-scenes access for you.",

"That’s a secret move… only I know the cheat code.",

"This isn’t the backstage pass you were hoping for.",

"If you right-click three times, a genie still won’t appear.",

"There’s nothing to see here… or is there?",

"Ah, a fellow explorer! But some secrets must remain hidden.",

"Hoping for a VIP tour? Sorry, this area is restricted.",

"Right-clicking is like pineapple on pizza… controversial!",

"Whoa! You almost found the hidden treasure. Almost.",

"Trying to peek behind the magic curtain? The magician never reveals their secrets!",

"Pay no attention to the code behind the curtain!’"

];

// Select a random message

var randomMessage = messages[Math.floor(Math.random() * messages.length)];

// Show the alert with the random message

alert(randomMessage);

});

</script>

____________________________________________________________

Choose Save and you’re all done.

One note, I did notice that right click also doesn’t work within editing a blog post, so not sure if that will be a problem, but hope this helps get you in the right direction.

Previous
Previous

80’s Ladies - Seattle Band

Next
Next

Bangkok, Thailand