Skip to content

Instantly share code, notes, and snippets.

@sincarne
Created March 5, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sincarne/ec19ed30e34402fcac22 to your computer and use it in GitHub Desktop.
Save sincarne/ec19ed30e34402fcac22 to your computer and use it in GitHub Desktop.
High Contrast JS test
// http://www.paciellogroup.com/blog/2011/10/detecting-if-images-are-disabled-in-browsers/
function isHighContrast() {
var e, c;
//Create a test div
e = document.createElement("div");
//Set its color style to something unusual
e.style.color = "rgb(31,41,59)";
//Attach to body so we can inspect it
document.body.appendChild(e);
//Use standard means if available, otherwise use the IE methods
c = document.defaultView ? document.defaultView.getComputedStyle(e, null).color : e.currentStyle.color;
//Delete the test DIV
document.body.removeChild(e);
//get rid of extra spaces in result
c = c.replace(/ /g, "");
//Check if we got back what we set
//If not we are in high contrast mode
if (c != "rgb(31,41,59)") {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment