Repository navigation
Expand file tree
/
Copy pathecho.html
More file actions
41 lines (40 loc) · 1.4 KB
/
Copy pathecho.html
File metadata and controls
41 lines (40 loc) · 1.4 KB
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
<!doctype html>
<html><head>
</head><body>
<p>WebViewJavascriptBridgeTests - echo.html</p>
<script>
function setupWebViewJavascriptBridge(callback) {
var bridge=window.WebViewJavascriptBridge||window.WKWebViewJavascriptBridge
if (bridge) { return callback(bridge); }
var callbacks=window.WVJBCallbacks||window.WKWVJBCallbacks
if (callbacks) { return callbacks.push(callback); }
window.WVJBCallbacks=window.WKWVJBCallbacks = [callback];
if(window.WKWebViewJavascriptBridge){
window.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage(null)
}else{
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('javaEchoToJs', { foo:'bar' }, function(response) {
if (response && response.foo == 'bar') {
responseCallback("Response from JS")
} else {
responseCallback("Failed")
}
})
})
//bridge.hasNativeMethod('javaEchoToJs',function(b){
// alert(b===true)
//})
})
</script>
</body></html>