I have this html in my assets folder.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript">
var publicKey = ""
function setPublicKey(key) {
publicKey = key;
var url = '<' + 'script src="https://<my_url>?onload=loadChallenge" async defer>' + '<' + '/script>'
document.write(url);
}
function loadChallenge() {
//do some stuff using the publicKey
new Thing( {public_key: publicKey } )
}
</script>
<div id="CAPTCHA"></div>
</body>
</html>
I need to load it into a webview, pass and set the publicKey, and then load the script that uses the onLoad param in the url.
So I'm loading my html into the webview and using this WebViewClient:
private val myWebViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
view?.loadUrl("javascript:setPublicKey($publicKey)")
}
}
document.write(url) isn't working. document.write("anything") isn't working.
I'm not married to this solution, I just need a solution that lets me load the html, then set the publicKey, and then load that script.
Any help would be greatly appreciated.