坚持不懈,持之以恒,方能在职业生涯不断提升自己。
jsBridge:混合app开发,h5与原声app通讯
const ua = navigator.userAgent const isAndroid = ua.indexOf(‘Android‘) > -1 || ua.indexOf(‘Linux‘) > -1 var jsBridge={}; /* 安卓 */ jsBridge.androidJsbridge=function(callback){ if(window.WebViewJavascriptBridge){ Toast(‘存在实例‘) callback(WebViewJavascriptBridge) }else{ document.addEventListener(‘WebViewJavascriptBridgeReady‘, () => { Toast(‘返回WebViewJavascriptBridge实例‘) Toast(WebViewJavascriptBridge) callback(WebViewJavascriptBridge) }, false) } } /* ios */ jsBridge.iosJsBridge=function(callback){ if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback(WebViewJavascriptBridge)) } window.WVJBCallbacks = [callback(WebViewJavascriptBridge)] Toast(‘返回WebViewJavascriptBridge实例‘) Toast(WebViewJavascriptBridge) var WVJBIframe = document.createElement(‘iframe‘) WVJBIframe.style.display = ‘none‘ WVJBIframe.src = ‘https://__bridge_loaded__‘ document.documentElement.appendChild(WVJBIframe) setTimeout(() => { document.documentElement.removeChild(WVJBIframe) }, 0) } jsBridge.init=(callback)=>{ if(isAndroid){ jsBridge.androidJsbridge(callback) }else{ return jsBridge.iosJsBridge(callback) } } const instance=jsBridge.init(callback)
原文:https://www.cnblogs.com/lihaohua/p/10637543.html