Created
March 26, 2012 08:16
-
-
Save justin-c-rounds/2203870 to your computer and use it in GitHub Desktop.
Checking user-agent strings
This file contains 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 checkUserAgent(matches) { | |
var i; | |
for (i = 0; i < matches.length; i += 1) { | |
if (window.navigator.userAgent.indexOf(matches[i]) !== -1) { | |
return true; | |
} | |
} | |
return false; | |
} | |
knownUserAgents = [ | |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20100101 Firefox/11.0', // Firefox | |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.54.16 (KHTML, like Gecko) Version/5.1.4 Safari/534.54.16', // Safari | |
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5', // iPhone3g Safari | |
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C148', // iPhone3g web app | |
'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3', // iPhone4 Safari | |
'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405', // iPhone4 web app | |
'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3', // iPad mobile Safari | |
'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176' // iPad web app | |
]; | |
if (checkUserAgent(knownUserAgents) === false) { | |
alert('This game has not been tested on this platform and may not work properly!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment