Skip to content

Instantly share code, notes, and snippets.

@nakamuuu
Created May 29, 2019 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakamuuu/72f818e1e413088e5564d3f03cc04ba7 to your computer and use it in GitHub Desktop.
Save nakamuuu/72f818e1e413088e5564d3f03cc04ba7 to your computer and use it in GitHub Desktop.
openUrl JSブリッジテスト用ページ
<head>
<script>
var bridge;
document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) {
bridge = event.bridge;
bridge.init(function(message, responseCallback) {});
}, false);
function runCallbackWithBridge(callback) {
if (bridge != null) {
callback(bridge);
} else {
document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) {
bridge = event.bridge;
bridge.init(function(message, responseCallback) {});
callback(bridge);
}, false);
}
}
function openUrlForIos(url, title) {
runCallbackWithBridge(function(bridge) {
bridge.callHandler('openUrl', {'url': url});
});
}
function openUrlForAndroid(url, title) {
droid.openUrl(title, url);
}
</script>
</head>
<body>
<input type="button" value="openUrl (for iOS)" onclick="openUrlForIos('https://www.google.co.jp/', 'タイトル');">
<input type="button" value="openUrl (for Android)" onclick="openUrlForAndroid('https://www.google.co.jp/', 'タイトル');">
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment