Created
January 13, 2015 15:35
-
-
Save atmd83/d3b396a8420619c71dfa to your computer and use it in GitHub Desktop.
Checking a white list of supported browsers for javascript applications
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
(function (agent) { | |
var whiteList = { // example of a whitelist. browser name/version and a UA substring | |
"firefox31" : "Firefox/31.0", | |
"IE10" : "MSIE 10.0", | |
"chrome37" : "Chrome/37", | |
"chrome38" : "Chrome/38", | |
"chrome39" : "Chrome/39" | |
}, validBrowser = false; | |
for(var browser in whiteList){ | |
if(agent.indexOf(whiteList[browser]) > -1){ | |
validBrowser = true; | |
break; | |
} | |
} | |
if(!validBrowser){ | |
// You're not supporting this browser. Do something. | |
} | |
})(navigator.userAgent); | |
/* | |
* N.b. While user agent strings can not always be trusted, something you need to sniff the UA string. | |
* (Yeah, yeah feature detection and all that but sometimes no because of reasons) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment