mx-h5-jsbridge
Version:
支持H5和iOS/Android/Harmony进行双向通信,H5 和原生通讯只需一套代码
11 lines (10 loc) • 516 B
JavaScript
export default function connectJSBridge(callback) {
if (window.WebViewJavascriptBridge) return callback(window.WebViewJavascriptBridge)
if (window.WVJBCallbacks) return window.WVJBCallbacks.push(callback)
window.WVJBCallbacks = [callback]
const WVJBIframe = document.createElement('iframe')
WVJBIframe.style.display = 'none'
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'
document.documentElement.appendChild(WVJBIframe)
setTimeout(() => { document.documentElement.removeChild(WVJBIframe) }, 0)
}