有没有办法检测用户使用的是什么设备?

Is there a way to detect what device a user is using?

假设我想向用户提供一个字符串,"You are using a..." 后跟他们的设备。

例如 Google Nexus 7、Dell Chromebook 13、Samsung Galaxy J3、Apple Macbook Pro...无论他们的设备是什么。特别是他们设备的型号。

例如,我见过 Spotify 这样做。这可以使用 JS 吗?

我知道存在用户代理嗅探,但它没有我希望的那么详细。

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 // some code..
}

或者您可以使用 jQuery 这个:

var customizeForDevice = function(){
    var ua = navigator.userAgent;
    var checker = {
      iphone: ua.match(/(iPhone|iPod|iPad)/),
      blackberry: ua.match(/BlackBerry/),
      android: ua.match(/Android/)
    };
    if (checker.android){
        $('.android-only').show();
    }
    else if (checker.iphone){
        $('.idevice-only').show();
    }
    else if (checker.blackberry){
        $('.berry-only').show();
    }
    else {
        $('.unknown-device').show();
    }
}