Last active
October 12, 2015 08:18
-
-
Save thomasjbradley/3997727 to your computer and use it in GitHub Desktop.
js: detect if images on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://www.456bereastreet.com/archive/201211/using_javascript_to_check_if_images_are_enabled/ | |
Will add the class `images-on` to <body> | |
Check if images are disabled: http://www.paciellogroup.com/blog/2011/10/detecting-if-images-are-disabled-in-browsers/ | |
*/ | |
(function() { | |
var image = new Image(); | |
image.onload = function() { | |
if (image.width > 0) { | |
document.documentElement.className += (document.documentElement.className != '') ? ' images-on' : 'images-on'; | |
} | |
}; | |
image.src = 'px.png'; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment