Skip to content

Instantly share code, notes, and snippets.

@agassiyzh
Created September 3, 2014 06:28
Show Gist options
  • Save agassiyzh/7d1b4d8d9669d339d974 to your computer and use it in GitHub Desktop.
Save agassiyzh/7d1b4d8d9669d339d974 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
</head>
<body style="width: 320px">
<script>
window.onerror = function(err) {
}
function connectWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) {
callback(WebViewJavascriptBridge)
} else {
document.addEventListener('WebViewJavascriptBridgeReady', function() {
callback(WebViewJavascriptBridge)
}, false)
}
}
connectWebViewJavascriptBridge(function(bridge) {
bridge.init(function(message, responseCallback) {
if (responseCallback) {
responseCallback("Right back atcha")
}
})
bridge.registerHandler('payForAlipay', function(data, responseCallback) {
var responseData = { 'Javascript Says':'Right back atcha!' }
responseCallback(responseData)
})
var button = document.getElementById('btn')
button.onclick = function(e) {
e.preventDefault()
var data = {
"tradeNO" : "58123",
"price" : "0.01",
"productName" : "Minila Air",
"productDescription" : "Buletooth",
"notifyURL" : "http://qiugonglue.com"
}
bridge.callHandler("payForAlipay",data, function(responseData) {
alert("I got a response!")
responseCallback(responseData)
})
}
})
</script>
<button id='btn'>click me</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment