通过javascirptBridge与手机端进行交互

<div>
<p>案例:</p>


<div><button id='QRCodeButton' style="font-size:12px">二维码扫描</button><span><a class="codeContent" style="margin-left:20px;" href="javascript:;" rel="showQRCode">查看源码</a></span></div>
<div style="margin-top:20px;"><button id='selectPButton' style="font-size:12px">选人</button><span><a class="codeContent" style="margin-left:20px;" href="javascript:;" rel="showSelectPerson">查看源码</a></span></div>
<div style="margin-top:20px;"><button id='cameraButton' style="font-size:12px">手机相机</button><span><a class="codeContent" style="margin-left:20px;" href="javascript:;" rel="showCamera">查看源码</a></span></div>
<div style="margin-top:20px;"><button id='albumSelectButton' style="font-size:12px">本地相册选图片</button><span><a class="codeContent" style="margin-left:20px;" href="javascript:;" rel="showAlbumSelect">查看源码</a></span></div>
<div style="margin-top:20px;"><button id='albumPreviewButton' style="font-size:12px">多图相册效果</button><span><a class="codeContent" style="margin-left:20px;" href="javascript:;" rel="showAlbumPreview">查看源码</a></span></div>
<div style="margin-top:20px;">
	<div id="showQRCode" style="display:none;">
		<br>JS代码如下:
		<br>function connectWebViewJavascriptBridge(callback) {
		<br>if (window.WebViewJavascriptBridge) {
		<br>callback(WebViewJavascriptBridge)
		<br>} else {
		<br>document.addEventListener('WebViewJavascriptBridgeReady', function() {
		<br>callback(WebViewJavascriptBridge)
		<br}, false)
		<br>}
		<br>}
		<br>connectWebViewJavascriptBridge(function(bridge) {
		<br>bridge.init(function(message, responseCallback) {
		<br>var data = { 'Javascript Responds':'Wee!' }
		<br>responseCallback(data)
		<br>})
		<br>$("#QRCodeButton").click( function(e) {
		<br>e.preventDefault()
		<br>bridge.callHandler('onQRCodeScan', {}, function(result) {
		<br>alert(result);
		<br>})
		<br>});
	</div>
	<div id="showSelectPerson" style="display:none;">
		<br>JS代码如下:
		<br>function connectWebViewJavascriptBridge(callback) {
		<br>if (window.WebViewJavascriptBridge) {
		<br>callback(WebViewJavascriptBridge)
		<br>} else {
		<br>document.addEventListener('WebViewJavascriptBridgeReady', function() {
		<br>callback(WebViewJavascriptBridge)
		<br}, false)
		<br>}
		<br>}
		<br>connectWebViewJavascriptBridge(function(bridge) {
		<br>bridge.init(function(message, responseCallback) {
		<br>var data = { 'Javascript Responds':'Wee!' }
		<br>responseCallback(data)
		<br>})
		<br>$("#selectPButton").click( function(e) {
		<br>e.preventDefault()
		<br>bridge.callHandler('onPplSelect', {}, function(result) {
		<br>alert(result);
		<br>})
		<br>});
	</div>
	<div id="showCamera" style="display:none;">
		<br>JS代码如下:
		<br>function connectWebViewJavascriptBridge(callback) {
		<br>if (window.WebViewJavascriptBridge) {
		<br>callback(WebViewJavascriptBridge)
		<br>} else {
		<br>document.addEventListener('WebViewJavascriptBridgeReady', function() {
		<br>callback(WebViewJavascriptBridge)
		<br}, false)
		<br>}
		<br>}
		<br>connectWebViewJavascriptBridge(function(bridge) {
		<br>bridge.init(function(message, responseCallback) {
		<br>var data = { 'Javascript Responds':'Wee!' }
		<br>responseCallback(data)
		<br>})
		<br>$("#cameraButton").click( function(e) {
		<br>e.preventDefault()
		<br>bridge.callHandler('onPicTake', {}, function(result) {
		<br>alert(result);
		<br>})
		<br>});
	</div>
	<div id="showAlbumSelect" style="display:none;">
		<br>JS代码如下:
		<br>function connectWebViewJavascriptBridge(callback) {
		<br>if (window.WebViewJavascriptBridge) {
		<br>callback(WebViewJavascriptBridge)
		<br>} else {
		<br>document.addEventListener('WebViewJavascriptBridgeReady', function() {
		<br>callback(WebViewJavascriptBridge)
		<br}, false)
		<br>}
		<br>}
		<br>connectWebViewJavascriptBridge(function(bridge) {
		<br>bridge.init(function(message, responseCallback) {
		<br>var data = { 'Javascript Responds':'Wee!' }
		<br>responseCallback(data)
		<br>})
		<br>$("#albumSelectButton").click( function(e) {
		<br>e.preventDefault()
		<br>ridge.callHandler('onAlbumSelect', {}, function(result) {
		<br>alert(result);
		<br>})
		<br>});
	</div>
	<div id="showAlbumPreview" style="display:none;">
		<br>JS代码如下:
		<br>function connectWebViewJavascriptBridge(callback) {
		<br>if (window.WebViewJavascriptBridge) {
		<br>callback(WebViewJavascriptBridge)
		<br>} else {
		<br>document.addEventListener('WebViewJavascriptBridgeReady', function() {
		<br>callback(WebViewJavascriptBridge)
		<br}, false)
		<br>}
		<br>}
		<br>connectWebViewJavascriptBridge(function(bridge) {
		<br>bridge.init(function(message, responseCallback) {
		<br>var data = { 'Javascript Responds':'Wee!' }
		<br>responseCallback(data)
		<br>})
		<br>$("#albumPreviewButton").click( function(e) {
		<br>e.preventDefault()
		<br>bridge.callHandler('onAlbumPreview', {"data":"http://oss.iclass.cn/smallfiles/origin/1423794165654amvau.jpg,http://oss.iclass.cn/smallfiles/origin/1423794170097eefyq.jpg,http://oss.iclass.cn/smallfiles/origin/1423794176383flxsg.jpg|1"}, function(result) {
		<br>alert(result);
		<br>})
		<br>});
	</div>
</div>
<script type="text/javascript" src="/api/public/js/min/jquery-1.8.3.js"></script>
<script type="text/javascript">
	$(".codeContent").click(function(){
		var idName=$(this).attr("rel");
		$("#"+idName).attr("style","");
		$("#"+idName).siblings().attr("style","display:none;");
	});
	function connectWebViewJavascriptBridge(callback) {
		if (window.WebViewJavascriptBridge) {
			callback(WebViewJavascriptBridge)
		} else {
			document.addEventListener('WebViewJavascriptBridgeReady', function() {
				callback(WebViewJavascriptBridge)
			}, false)
		}
	}
	
	connectWebViewJavascriptBridge(function(bridge) {
		bridge.init(function(message, responseCallback) {
			var data = { 'Javascript Responds':'Wee!' }
			responseCallback(data)
		})
		
		$("#QRCodeButton").click( function(e) {
			e.preventDefault()
			bridge.callHandler('onQRCodeScan', {}, function(result) {
				alert(result);
			})
		});
		$("#selectPButton").click( function(e) {
			e.preventDefault()
			bridge.callHandler('onPplSelect', {}, function(result) {
				alert(result);
			})
		});
		$("#cameraButton").click( function(e) {
			e.preventDefault()
			bridge.callHandler('onPicTake', {}, function(result) {
				alert(result);
			})
		});
		$("#albumSelectButton").click( function(e) {
			e.preventDefault()
			bridge.callHandler('onAlbumSelect', {}, function(result) {
				alert(result);
			})
		});
		$("#albumPreviewButton").click( function(e) {
			e.preventDefault()
			bridge.callHandler('onAlbumPreview', {"data":"http://oss.iclass.cn/smallfiles/origin/1423794165654amvau.jpg,http://oss.iclass.cn/smallfiles/origin/1423794170097eefyq.jpg,http://oss.iclass.cn/smallfiles/origin/1423794176383flxsg.jpg|1"}, function(result) {
				alert(result);
			})
		});
	
	})
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值