Skip to content

Instantly share code, notes, and snippets.

@namklabs
Created September 14, 2012 15:33
Show Gist options
  • Save namklabs/3722686 to your computer and use it in GitHub Desktop.
Save namklabs/3722686 to your computer and use it in GitHub Desktop.
Prevent Image Downloads
$(function(){
$.each( $("img"), function(){
$(this).parents().show().end().show().css({
"background-image": "url(" + $(this).attr("src") + ")",
"background-size": "100%",
"width": $(this).width(),
"height": $(this).height()
}); // show all images so that their size isn't 0x0 - showing parents enables children to be shown too. Then replace src with decoy image and make background the real image with the proper scale in case the image is scaled.
$(this).attr("src","./image/cache/empty.png");
});
});
// I think this is really against the nature of the web to try and "prevent" the download of images, but a client wanted this so it had to be done despite my personal convictions. If you use this code, please realize that you are making a sad attempt at usurping how the internet works. If someone can see an image on your website, then that image is already downloaded onto their computer. It's just in a temporary location that makes it difficult but not impossible for them to find and exploit. I do advise that we all follow copyright laws, but copyrighted images are 'copied' each time they are displayed in a person's web browser. If you don't want images to be downloaded, don't put them on the internet. The end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment