Created
May 12, 2014 23:00
-
-
Save dgtlmonk/9962d900efc0f5aa6d99 to your computer and use it in GitHub Desktop.
Mobile OS detect
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
<script type="text/javascript" charset="utf-8"> | |
"use strict"; | |
var ua = navigator.userAgent; | |
var checker = { | |
iphone: ua.match(/(iPhone|iPod|iPad)/), | |
blackberry: ua.match(/BlackBerry/), | |
android: ua.match(/Android/) | |
}; | |
if (checker.iphone) setStatus('iOS'); | |
if (checker.blackberry:) setStatus('BlackBerry'); | |
if (checker.android:) setStatus('Android'); | |
// log status string | |
function setStatus( s ) : void { | |
document.getElementById('statusText').innerHTML = 'Device Type: ' + s; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment