获取表单用户浏览器信息

需求:获取用户浏览器信息

 1     //form
 2     function getOsVersion() {
 3         var u = navigator.userAgent, version = ''
 4         if (u.indexOf('Mac OS X') > -1) {
 5             // ios
 6             var regStr_saf = /OS [\d._]*/gi
 7             var verinfo = u.match(regStr_saf)
 8             version = 'IOS' + (verinfo + '').replace(/[^0-9|_.]/ig, '').replace(/_/ig, '.')
 9         } else if (u.indexOf('Android') > -1 ||
10             u.indexOf('Linux') > -1) {
11             // android
12             version = 'Android' + u.substr(u.indexOf('Android') + 8, u.indexOf(';', u.indexOf('Android')) - u.indexOf('Android') - 8)
13         } else if (u.indexOf('BB10') > -1) {
14             // 黑莓bb10系统
15             version = 'blackberry' + u.substr(u.indexOf('BB10') + 5, u.indexOf(';', u.indexOf('BB10')) - u.indexOf('BB10') - 5)
16         } else if (u.indexOf('IEMobile') > -1) {
17             // windows phone
18             version = 'winphone' + u.substr(u.indexOf('IEMobile') + 9, u.indexOf(';', u.indexOf('IEMobile')) - u.indexOf('IEMobile') - 9)
19         } else {
20             var userAgent = navigator.userAgent.toLowerCase()
21             if (userAgent.indexOf('windows nt 5.0') > -1) {
22                 version = 'Windows 2000'
23             } else if (userAgent.indexOf('windows nt 5.1') > -1 || userAgent.indexOf('windows nt 5.2') > -1) {
24                 version = 'Windows XP'
25             } else if (userAgent.indexOf('windows nt 6.0') > -1) {
26                 version = 'Windows Vista'
27             } else if (userAgent.indexOf('windows nt 6.1') > -1 || userAgent.indexOf('windows 7') > -1) {
28                 version = 'Windows 7'
29             } else if (userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows 8') > -1) {
30                 version = 'Windows 8'
31             } else if (userAgent.indexOf('windows nt 6.3') > -1) {
32                 version = 'Windows 8.1'
33             } else if (userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows nt 10.0') > -1) {
34                 version = 'Windows 10'
35             } else {
36                 version = 'Unknown'
37             }
38         }
39         return version
40     }
41     $("input[name='title']").val(window.location.href);
42     $("input[name='ref']").val(window.location.href);
43     $("input[name='screenwh']").val(window.screen.width + " x " + window.screen.height);
44     $("input[name='language']").val(navigator.language||navigator.userLanguage);
45     $("input[name='os']").val(getOsVersion());
46     $("input[name='browser']").val(navigator.userAgent);

 

posted @ 2021-11-27 14:33  Arya-Wang  阅读(46)  评论(1)    收藏  举报