检测客户端信息ua-parser-js


ua-parser-js用于检测客户端信息

引入

CDN引入:

1
<script src="https://cdn.jsdelivr.net/npm/ua-parser-js@0/dist/ua-parser.min.js"></script>

NPM引入:

1
2
npm i ua-parser-js
import UAParser from 'ua-parser-js'

使用

1
2
3
var parser = new UAParser();
var result = parser.getResult();
console.log(result);

api

1
2
3
4
5
6
7
8
9
var parser = new UAParser();
var result = parser.getResult();
result.browser //{name: "Chrome", version: "66.0.3359.139", major: "66"}
result.device //{vendor: "Apple", model: "iPhone", type: "mobile"}
result.os //{name: "iOS", version: "11.0"}
result.os.version //11.0
result.engine //{name: "WebKit", version: "604.1.38"}
result.cpu

原生js判断浏览器信息

1
2
3
if(!!window.ActiveXObject || "ActiveXObject" in window){
document.body.innerHTML = '<h1 style="font-size:30px;">请使用chrome浏览器打开此页!</h1>';
}
-------------本文结束感谢您的阅读-------------