Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.