如何检测设备是从哪个PC或移动设备发出请求

这个问题在这里已经有了答案:

  • 在jQuery中检测移动设备的最佳方式是什么? 49个答案

  • 是的,你可以从请求的用户代理中辨别出来。 为自己编写正则表达式或使用现成的npm模块设备

    代码参考:

    var device = require('device')
    app.get('/', function(req, res) {
        var ua = req.headers['user-agent'];
        if(device.is('phone')){
           console.log('device is phone');
        }else if(device.is('tablet')){
           console.log('device is tablet');
        }else  if(device.is('desktop')){
           console.log('device is desktop');
        }else {
           console.log('device is something else');
        }
    });
    
    链接地址: http://www.djcxy.com/p/84059.html

    上一篇: How to detect a device is pc or mobile from which request is made

    下一篇: JS detect if mobile and set condition