方法一: HTML+ 封装好的方法,额外配置,使用指定方法打包才可用
属性:
imei: 设备的国际移动设备身份码
imsi: 设备的国际移动用户识别码
model: 设备的型号
vendor: 设备的生产厂商
uuid: 设备的唯一标识
参考地址: /doc/zh_cn/device.html
方法二:引用插件mobile-detect.js,可以获取
console.log(md.mobile());//'Sony'
console.log(md.phone());//'Sony'
console.log(md.tablet());//null
console.log(md.userAgent());//'Safari'
console.log(md.os());//'AndroidOS'
console.log(md.is('iPhone'));//false
console.log(md.is('bot'));//false
console.log(md.version('Webkit'));//534.3
console.log(md.versionStr('Build'));//'4.1.A.0.562'
console.log(md.match('playstation|xbox'));//false
参考地址:http://hgoebl.github.io/mobile-detect.js
下载地址:/hgoebl/mobile-detect.js/
方法三:调用app的native方法,jsBrage交互获取json字符串
//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);
});
}
}
})();