App里webview调用ios或者安卓的方法(内嵌h5页面调用app原生方法)
安卓调用
function login(){
window.{app包名}.login();
}
IOS调用
var openWindow = function () { };
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) {
var openWindow = function(urlAddress){
bridge.callHandler('OpenNewPageWithUrl', {'urlAddress':urlAddress}, function responseCallback(responseData) {
console.log("registerOCmethod:", responseData)
})
}
});