How to detect a device is pc or mobile from which request is made
This question already has an answer here:
Yes, you can discern from user agent of request. Write the regex for that yourself or use a ready-made npm module device
code reference:
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/84060.html
上一篇: Javascript中的移动设备检测