使用jsBridge和原生IOS、Android交互

使用jsBridge和原生IOS、Android交互,有两种方式

第一种:

function testClick() {
       	   var data = {
               title: '宜信宜人贷',
               url: 'http://wap.yirendai.com/new/?siteId=2224',
               desc: "网页发消息给webview"
           };
           window.WebViewJavascriptBridge.send(data, function (responseData) {
               console.log("客户端返回的值:" + responseData);
           });
        }

第二种:

function getLoanHeight(height){
			var data = {
			 	"height":height,
			};
		  
			setupWebViewJavascriptBridge(function (bridge) {
				bridge.callHandler('getLoanHeight', data, function (responseData) {

				});
			});
		}
		
		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)
		}


你可能感兴趣的:(javascript)