Skip to content

Commit be953b0

Browse files
author
fangj
committed
update HTML bridge part
1 parent e5087b0 commit be953b0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,49 @@ To use a WebViewJavascriptBridge in your chrome extension:
4747
})
4848
}, false)
4949

50+
HTML
51+
----------
52+
To use a WebViewJavascriptBridge in your HTML page:
53+
1) Add "bridgeServerHtml.js" and "bridgeClientHtml.js" to your page. bridgeServerHtml.js Must be first and bridgeClientHtml.js Must be last.
54+
55+
<script src="bridgeServerHtml.js"></script> <!--muse be first -->
56+
<script src="user_client.js"></script>
57+
<script src="user_server.js"></script>
58+
<script src="bridgeClientHtml.js"></script> <!--muse be last -->
59+
60+
2) Set up the background side:
61+
62+
console.log("user_server.js called!");
63+
bridge.sinit(function(data,responseCallback){
64+
console.log("Received message from javascript: "+data);
65+
if(responseCallback){
66+
responseCallback("Right back atcha");
67+
}
68+
})
69+
function serverSend(){
70+
bridge.ssend("Well hello there");
71+
bridge.ssend("Give me a response, will you?", function(responseData) {
72+
console.log("Background got its response! "+responseData);
73+
})
74+
}
75+
setTimeout(serverSend,1000);
76+
77+
3) Set up the foreground side:
78+
79+
console.log("user_client.js called!");
80+
document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) {
81+
var bridge = event.bridge
82+
bridge.init(function(message, responseCallback) {
83+
alert('Received message: ' + message)
84+
if (responseCallback) {
85+
responseCallback("Right back atcha")
86+
}
87+
})
88+
bridge.send('Hello from the javascript')
89+
bridge.send('Please respond to this', function responseCallback(responseData) {
90+
console.log("Javascript got its response", responseData)
91+
})
92+
}, false)
5093

5194
IOS
5295
----------

0 commit comments

Comments
 (0)