Skip to content

Instantly share code, notes, and snippets.

@dgtlmonk
Created May 12, 2014 23:00
Show Gist options
  • Save dgtlmonk/9962d900efc0f5aa6d99 to your computer and use it in GitHub Desktop.
Save dgtlmonk/9962d900efc0f5aa6d99 to your computer and use it in GitHub Desktop.
Mobile OS detect
<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