2025-04-19 15:05:22 +08:00

33 lines
1.1 KiB
HTML

<!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>