-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathecho.html
32 lines (31 loc) · 1.09 KB
/
echo.html
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
<!doctype html>
<html><head>
</head><body>
<p>WebViewJavascriptBridgeTests - echo.html</p>
<script>
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 = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
setupWebViewJavascriptBridge(function(bridge) {
bridge.registerHandler('echoHandler', function(data, responseCallback) {
responseCallback(data)
})
bridge.registerHandler('jsRcvResponseTest', function(data, responseCallback) {
bridge.callHandler('objcEchoToJs', { foo:'bar' }, function(response) {
if (response && response.foo == 'bar') {
responseCallback("Response from JS")
} else {
responseCallback("Failed")
}
})
})
})
</script>
</body></html>