Skip to content

Instantly share code, notes, and snippets.

@atmd83
Created January 13, 2015 15:35
Show Gist options
  • Save atmd83/d3b396a8420619c71dfa to your computer and use it in GitHub Desktop.
Save atmd83/d3b396a8420619c71dfa to your computer and use it in GitHub Desktop.
Checking a white list of supported browsers for javascript applications
(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