Skip to content

Instantly share code, notes, and snippets.

@thomasjbradley
Last active October 12, 2015 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasjbradley/3997727 to your computer and use it in GitHub Desktop.
Save thomasjbradley/3997727 to your computer and use it in GitHub Desktop.
js: detect if images on
/*
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