Created
March 5, 2015 18:39
-
-
Save sincarne/ec19ed30e34402fcac22 to your computer and use it in GitHub Desktop.
High Contrast JS test
This file contains hidden or 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.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