首页 > 移动平台 > 详细

IOSJSBRIGE商品内容模板

时间:2015-11-24 21:08:44      阅读:195      评论:0      收藏:0      [点我收藏+]
<p>
	内容
</p>
<script>
            window.onerror = function(err) {
                log(‘window.onerror: ‘ + err)
            }
            function connectWebViewJavascriptBridge(callback) {
                if (window.WebViewJavascriptBridge) {
                    callback(WebViewJavascriptBridge)
                } else {
                    document.addEventListener(‘WebViewJavascriptBridgeReady‘, function() {
                        callback(WebViewJavascriptBridge)
                    }, false)
                }
            }
            connectWebViewJavascriptBridge(function(bridge) {
                var uniqueId = 1
                function log(message, data) {
//                var log = document.getElementById(‘log‘)
//                var el = document.createElement(‘div‘)
//                el.className = ‘logLine‘
//                el.innerHTML = uniqueId++ + ‘. ‘ + message + ‘:<br />
‘ + JSON.stringify(data)
//                if (log.children.length) { log.insertBefore(el, log.children[0]) }
//                else { log.appendChild(el) }
                }
                bridge.init(function(message, responseCallback) {
                    log(‘JS got a message‘, message)
                    var data = { ‘Javascript Responds‘:‘Wee!‘ }
                    log(‘JS responding with‘, data)
                    responseCallback(data)
                })
                bridge.registerHandler(‘testJavascriptHandler‘, function(data, responseCallback) {
                    log(‘ObjC called testJavascriptHandler with‘, data)
                    var responseData = { ‘Javascript Says‘:‘Right back atcha!‘ }
                    log(‘JS responding with‘, responseData)
                    responseCallback(responseData)
                })
                //测试回调
                var callbackButton = document.getElementById(‘buttons‘)
                callbackButton.onclick = function(e) {
                    e.preventDefault()
                    log(‘JS calling handler "testObjcCallback"‘)
                    bridge.callHandler(‘testObjcCallback‘, {‘m_id‘: ‘2999‘}, function(response) {
                        log(‘JS got response‘, response)
                    })
                }
            })
        </script>
<p>
	<br />
</p>
<p>
	<br />
</p>
<div id="buttons">
	价格:500元 <a href="#">查看详情</a> 
	<div id="log">
	</div>
</div>
<p>
	<br />
</p>

  

IOSJSBRIGE商品内容模板

原文:http://www.cnblogs.com/lsl8966/p/4992810.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!