随笔 - 159  文章 - 2  评论 - 0  阅读 - 61805

IOSJSBRIGE商品内容模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<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>

  

posted on   lsl8966  阅读(153)  评论(0编辑  收藏  举报
< 2025年1月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示