原文:http://blog.csdn.net/jacman/article/details/49330097
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)
}
function h() {
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if(isiOS) {
console.log('ios调用');
setupWebViewJavascriptBridge(function (bridge){
bridge.callHandler('BackFunc','hello oc'); //BackFunc为oc端自定义函数
});
} else if(isAndroid) {
console.log('安卓调用');
android.finishStockWeb();//此方法为安卓端自定义函数
} else {
return ;
}
}