标签:response 支持 href function reg string set 插件 tee
function setupWebViewJavascriptBridge (callback) {
if (window.WebViewJavascriptBridge) {
return callback(window.WebViewJavascriptBridge)
}
if (window.WVJBCallbacks) {
return window.WVJBCallbacks.push(callback)
}
window.WVJBCallbacks = [callback]
let WVJBIframe = document.createElement(‘iframe‘)
WVJBIframe.style.display = ‘none‘
WVJBIframe.src = ‘https://__bridge_loaded__‘
document.documentElement.appendChild(WVJBIframe)
setTimeout(() => {
document.documentElement.removeChild(WVJBIframe)
}, 0)
}
function callhandler (name, data, callback) {
setupWebViewJavascriptBridge(function (bridge) {
bridge.callHandler(name, data, callback)
})
}
callhandler(functionName: string, params: object, res => {})
registerhandler (name, callback) {
// 安卓
window[name] = res => {
let data = JSON.parse(res)
callback(data)
}
// IOS
setupWebViewJavascriptBridge(function (bridge) {
bridge.registerHandler(name, function (data, responseCallback) {
callback(data, responseCallback)
})
})
}
window.HTTP_TEST.functionName()
window[‘functionName‘] = res => {}
来源:https://segmentfault.com/a/1190000016879200
标签:response 支持 href function reg string set 插件 tee
原文地址:https://www.cnblogs.com/lovellll/p/10126110.html