Skip to content

Instantly share code, notes, and snippets.

@foo9
Created February 6, 2013 07:25
Show Gist options
  • Save foo9/4720927 to your computer and use it in GitHub Desktop.
Save foo9/4720927 to your computer and use it in GitHub Desktop.
/*!
* jQuery preventDLImg - prevent download image
*
* Copyright 2013, Kouta Fukuhara
*
* Released under the MIT license.
*
* $('img').preventDLImg();
*/
;(function(e){e.fn.preventDLImg=function(){var b,c,d,a;return this.each(function(){if("IMG"!==this.tagName)return!0;b=this.src;this.src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";c=this.width;d=this.height;a=c+"px "+d+"px";this.style.backgroundImage="url("+b+")";this.style.userSelect="none";this.style.webkitUserSelect="none";this.style.MozUserSelect="none";this.style.OUserSelect="none";this.setAttribute("unselectable","on");this.style.backgroundSize=a;this.style.webkitBackgroundSize=
a;this.style.MozBackgroundSize=a;this.style.ObackgroundSize=a;this.style.backgroundRepeat="no-repeat"})}})(jQuery||Zepto);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment