这两天在研究如何区分手机用户(竖屏)和电脑用户(横屏),以此来做到使用不同的ui、展现不同的页面。
node.js中,输入以下代码来康康结果:
const http = require("http");
var server = http.createServer(function(req,res){
console.log(req.headers);
res.end(req.headers['user-agent']);
});
server.listen(80);
console.log("服务已运行于端口80!");
访问localhost,结果如下(电脑端):
手机端结果:
终端输出:
服务已运行于端口80!
{
host: 'localhost',
connection: 'keep-alive',
'cache-control': 'max-age=0',
'sec-ch-ua': '" Not A;