1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>测试js</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <script src="jquery-1.8.3.min.js"></script>
7 <style type="text/css">.content{color: red;font-size: 15px;}</style>
8 </head>
9 <body>
10 展示设备
11 <p class="content"></p>
12 <p class="agentsinfo"></p>
13 </body>
14 <script type="text/javascript">
15 var userAgentInfo = navigator.userAgent;
16 function IsAgent() {
17 var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod", "Windows"];
18 var res = '';
19 for (var v = 0; v < Agents.length; v++) {
20 if (userAgentInfo.indexOf(Agents[v]) > 0) {
21 res = Agents[v];
22 break;
23 }
24 }
25 return res;
26 }
27 console.log(navigator.userAgent);
28
29 console.log('这部设备是:'+IsAgent());
30 $('.agentsinfo').html('设备信息:'+userAgentInfo);
31 </script>
32 </html>
记得更换jquery地址