Last active
October 31, 2017 10:26
-
-
Save umair-khokhar/705f1f5343bb422d59aaeba546994c30 to your computer and use it in GitHub Desktop.
Identifying user device type
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
<span id="txtDevice"></span> | |
<script> | |
var deviceDetector=function(){var b=navigator.userAgent.toLowerCase(),a=function(a){void 0!==a&&(b=a.toLowerCase());return/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(b)?"tablet":/(mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard)/.test(b)?"phone":"desktop"};return{device:a(),detect:a,isMobile:"desktop"!=a()?!0:!1,userAgent:b}}(); | |
</script> | |
<script> | |
var device = ""; | |
document.addEventListener("DOMContentLoaded", function(event) { | |
if(deviceDetector.device == 'desktop') { | |
if (navigator.appVersion.indexOf("Win")!=-1) device="PC"; | |
else if (navigator.appVersion.indexOf("Mac")!=-1) device="Mac"; | |
else if (navigator.appVersion.indexOf("X11")!=-1) device="UNIX"; | |
else if (navigator.appVersion.indexOf("Linux")!=-1) device="Linux"; | |
} else{ | |
if(deviceDetector.device == 'tablet') | |
device="tablet"; | |
else | |
device="smartphone"; | |
} | |
document.getElementById("txtDevice").innerHTML = device; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment