js获取系统信息

方法一: HTML+  封装好的方法,额外配置,使用指定方法打包才可用

属性:

  • imei: 设备的国际移动设备身份码
  • imsi: 设备的国际移动用户识别码
  • model: 设备的型号
  • vendor: 设备的生产厂商
  • uuid: 设备的唯一标识

参考地址: http://www.html5plus.org/doc/zh_cn/device.html

 参考:https://www.cnblogs.com/dontes/p/9075877.html

方法二:引用插件mobile-detect.js,可以获取

  1. console.log( md.mobile() );          // 'Sony'  
  2. console.log( md.phone() );           // 'Sony'  
  3. console.log( md.tablet() );          // null  
  4. console.log( md.userAgent() );       // 'Safari'  
  5. console.log( md.os() );              // 'AndroidOS'  
  6. console.log( md.is('iPhone') );      // false  
  7. console.log( md.is('bot') );         // false  
  8. console.log( md.version('Webkit') );         // 534.3  
  9. console.log( md.versionStr('Build') );       // '4.1.A.0.562'  
  10. console.log( md.match('playstation|xbox') ); // false 

参考地址:http://hgoebl.github.io/mobile-detect.js

下载地址:https://github.com/hgoebl/mobile-detect.js/

 

方法三:调用app的native方法,jsBrage交互获取json字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//app交互
var flag;
var jsBridge = (function () {  
 
    function connectWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) {
            callback(WebViewJavascriptBridge);
        else {
            document.addEventListener('WebViewJavascriptBridgeReady'function () {
                callback(WebViewJavascriptBridge);
            }, false)
        }
    }
    connectWebViewJavascriptBridge(function (WebViewJavascriptBridge) {
        WebViewJavascriptBridge.init(function (message, responseCallback) {
 
        });
        WebViewJavascriptBridge.registerHandler("contactsList"function(data, responseCallback) {
            phoneNumbers=(data);
        });
        WebViewJavascriptBridge.registerHandler("contacts"function(data, responseCallback) {
            var datas=JSON.parse(data);
            if(currentNum==1){
                name1=datas.name;
                tel1=datas.phone;
                $("#firstTxtName").val(datas.name);
                $("#firstTxtTel").val(datas.phone);
            }else {
                name2=datas.name;
                tel2=datas.phone;
                $("#secondTxtName").val(datas.name);
                $("#secondTxtTel").val(datas.phone);
            }
        });
        WebViewJavascriptBridge.callHandler('getAppVersion', {}, function (response) { callback(response); });
        fn && fn();
 
    })
    return {
        init: function (fn) {
            connectWebViewJavascriptBridge(function (WebViewJavascriptBridge) {
                WebViewJavascriptBridge.init(function (message, responseCallback) {
 
                });
 
                fn && fn();
 
            })
        },
        copyWechat: function (obj) {
            WebViewJavascriptBridge.callHandler('copyWechat', { pageID: obj.pageID }, function (response) { });
        },
        saveQR: function (obj) {
            WebViewJavascriptBridge.callHandler('saveQR', { pageID: obj.pageID }, function (response) { });
        },
        showAppPage: function (obj) {
            WebViewJavascriptBridge.callHandler('showAppPage', { pageID: obj.pageID }, function (response) { });
        },
        jumpTo: function (obj) {
            WebViewJavascriptBridge.callHandler('jumpTo', {}, function (response) { });
        },
        showWebPage: function (obj) {
        WebViewJavascriptBridge.callHandler('showWebPage', { title: obj.title, pageUrl: obj.pageUrl }, function (response) { });
        },
        getSid: function (callback) {
            WebViewJavascriptBridge.callHandler('getSid', {}, function (response) { callback(response); });
        },      
        getContacts: function (callback) {
            WebViewJavascriptBridge.callHandler('getContacts', {}, function (response) { callback(response); });
        },
          getAppVersion: function (callback) {
              WebViewJavascriptBridge.callHandler('getAppVersion', {}, function (response) {
                flag=response;
                callback(response);
              });
          }
    }
})();
posted @ 2020-03-16 15:17  雨飞  阅读(1420)  评论(0编辑  收藏  举报