Category:JavaScript
Article From:https://www.cnblogs.com/dontes/p/9075877.html

 

Method 1: HTML+ encapsulation method, additional configuration, and use the specified method to pack.

Properties:

  • imei: Device’s international mobile device identity code
  • imsi: Device’s international mobile user identification code
  • model: Type of equipment
  • vendor: Manufacturer of equipment
  • uuid: The unique identity of the device

Reference address: http://www.html5plus.org/doc/zh_cn/device.html

 

Method two: reference plug-in mobile-detect.js can be obtained.

  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 

Reference address: http://hgoebl.github.io/mobile-detect.js

Download address: https://github.com/hgoebl/mobile-detect.js/

 

Method three: call the native method of app, and jsBrage get the JSON string.

  //appinteractiveVar flag;Var jsBridge = (function () {()Function connectWebViewJavascriptBridge (CALLback) {If (window.WebViewJavascriptBridge) {Callback (WebViewJavascriptBriDGE);} else {Document.addEventListener ('WebViewJavascriptBridgeReady', fun)Ction () {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;$("#firstTxtN"Ame ").Val (datas.name);$("#firstTxtTel").Val (datas.phone);}else {Name2=datas.name;Tel2=datas.phone;$("#secondT"XtName ").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);});}}}) () ();

  

Leave a Reply

Your email address will not be published. Required fields are marked *