device detection

device detection per user agent

by Ercan Cicek

HTML

<span></span>

JavaScript

// --- method unsafe
// --- if you want to use Android or Apple specified code, make sure DEVICE.ISWP is false, because WP devices sometimes have "Android" or "Apple" in their userAgents, too
(function() { 
var ua = navigator.userAgent,
    device = {
        isSmart: !!(ua.match(/(iPod|iPad|iPhone|Windows Phone|Android)/)),
        isApple: !!(ua.match(/(iPod|iPad|iPhone)/)),
        isAndroid: !!(ua.match(/(Android)/)),
        isWP: !! (ua.match(/(Windows Phone)/))
    };
var el = document.getElementsByTagName("span")[0];
el.innerHTML = "Smart: " + device.isSmart + 
               "<br />Apple: " + device.isApple + 
               "<br />Android: " + device.isAndroid + 
               "<br />Windows Phone: " + device.isWP;
})();