Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Photo Privacy

I recently visited a webpage and whenever i tried to right click anywhere on the page, it prompted me with a window that told me that this functions was disabled.

heres the webpage: http://www.annedarlingphotography.com/famous-black-photographers.html

i even tried inspecting the page and couldn't find if it was script running or what.

How do i implement this function into my webpage? or at least what is it called?

Even if you know the slightest information, let me know.

5 Answers

I agree with Tom, it's bad practice and creates a negative experience for the user. You shouldn't prevent the user from doing what feels natural to them. such as right clicking or using the back button.

With regards to protecting your photos, You should add a copyright declaration to the page and maybe consider adding a watermark to images and keeping the original images offline. However adding watermarks can ruin the look of the photo. You're not going to stop someone saving the images to their computer (if a user likes your photo enough to want to use it as their desktop background is that a bad thing?) but you can try and prevent anyone other than yourself making money from your work by keeping an eye out for anyone trying to pass off your work as their own.

Check out plagiarism.org which may contain some useful info. Also for finding where an image has been posted/reposted you can use google's reverse image search

Hope this helps!

Inspect the page again and you'll see scripts/fix.js. When you inspect fix.js about line 70 there's a function called isImageBlockImage that relies about the class ImageBlock in the containing div.

Good looking out.

Hi, I think they may be running a no right-click script, you can left click on items just fine and the source code isn't hidden.. If you're using Chrome, IE or Firefox you can press F12 to activate developer tools or CTRL + U to view source,

I viewed the source of the [famous-black-photographers.html](view-source:http://www.annedarlingphotography.com/famous-black-photographers.html) page and found this script

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
...

do you know what line and what folder did you find it in?

In famous-black-photographers.html should just be in root. Link to html page. [Link to generated source](view-source:http://www.annedarlingphotography.com/famous-black-photographers.html)

In the head of famous-black-photographers.html should just be in root. Link to html page. [Link to generated source](view-source:http://www.annedarlingphotography.com/famous-black-photographers.html) (line 23)

Hope this helps!

EDIT: Added line number / fixed things.

I find this type of website behavior very unhelpful as it doesn't stop someone taking the images. You can still left click and drag them to the desktop to save them, or look in the source or dev tools as already mentioned. On iOS you can still press and hold on an image to save it. Failing all of those you could "print screen" and crop it. If anyone wants the image they will be able to get it.

If applied to the whole page It does prevent you right clicking where you might want to:

  • copy an email address
  • copy a link
  • open a link in a new window or tab

These are all normal, useful behaviors that this type of script interferes with.

true, you pointed out some key points.

what suggestion do you think will be the best approach? i want my site to be usable but i want complete photo privacy.