app嵌入網頁與app互動
阿新 • • 發佈:2019-02-01
一、傳參給ios
// iosapp互動 function setupWebViewJavascriptBridge(callback) { if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); } if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); } window.WVJBCallbacks = [callback]; var WVJBIframe = document.createElement('iframe'); WVJBIframe.style.display = 'none'; WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'; document.documentElement.appendChild(WVJBIframe); setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) } setupWebViewJavascriptBridge(function(bridge) { bridge.callHandler( 'name', // ios裡定義的方法名 {'code': data.info.code}, // 要傳遞的引數陣列 function(response) {} ) })
二、傳參給安卓
// 安卓回撥
function customerParam(bridge, code) {
var data = {
code: code, // 要傳的引數
};
bridge.send(data, function (responseData) {
// alert('回撥');
});
}
window.appCustomer.customerParam(data.info.code);
注:appCustomer是安卓的類庫名,customerParam是方法名