Sto provando a chiamare una funzione javascript setGameName() tramite Android Webview Activity ma sta lanciando uncaught ReferenceError:setGameName not defined at :1
.non referenziate ReferenceError, chiamata funzione javascript tramite l'applicazione Android ..?
mio codice sorgente è il seguente:
webView2.setWebChromeClient(new WebChromeClient());
webView2.getSettings().setLightTouchEnabled(true);
webView2.getSettings().setJavaScriptEnabled(true);
webView2.addJavascriptInterface(jsInterface, "AndroidFunction");
webView2.loadUrl("file:///android_asset/www/index.html");
webView2.loadUrl("javascript:setGameName()");
codice HTML:
<body>
<script type="text/javascript">
function init() {
console.log("====== I am getting called::===");
var testVal = document.getElementById('playertextId').value;
AndroidFunction.proceedFurther(testVal);
};
function setGameName() {
console.log("====== Got the value===");
document.getElementById('gametextId').value;
};
</script>
</body>
Si sta caricando index.html bene, ma lanciando un'eccezione alla chiamata di funzione, Si prega di fornire una soluzione adeguata ..
Aggiornamento:
i have found the problem the page is not getting loaded at the time of function call..(Since on giving a time delay of 5000ms it is getting called..)!!
Ma come posso implementarlo allora ..?
@ ZeroflagL..Potresti per favore eleborare come devo implementarlo ..? –
[qui] (http://lexandera.com/2009/01/injecting-javascript-into-a-webview/) è un buon esempio. – zeroflagL
Grazie, ha funzionato per me :) –