获取 UserAgent
不考虑兼容性
我都是直接let user_agent = navigator.userAgent;
考虑兼容性
我会调用UAParser.js
库,github仓库地址
使用方法,在本地引用ua-parser.min.js
<script type="text/javascript" src="./ua-parser.min.js"></script>
<script type="text/javascript">
var parser = new UAParser();
var result = parser.getResult();
console.log(result.browser);
console.log(result.device);
console.log(result.os);
console.log(result.os.version);
console.log(result.engine.name);
console.log(result.cpu.architecture);
</script>