Próbuję wywołać funkcję javascript setGameName() przez Android Webview Activity, ale rzuca uncaught ReferenceError:setGameName not defined at :1
.uncaught ReferenceError, wywoływanie funkcji javascript za pośrednictwem aplikacji Android ..?
Mój kod źródłowy jest w następujący sposób:
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()");
kod 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>
To jest ładowanie index.html w porządku, ale rzuca wyjątek przy wywołaniu funkcji, Proszę dostarczyć odpowiednie rozwiązanie ..
Aktualizacja:
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..)!!
Ale jak mogę to wdrożyć ...?
@ ZeroflagL..Czy mógłbyś prosić o opracowanie, jak powinienem go wdrożyć ..? –
[tutaj] (http://lexandera.com/2009/01/injecting-javascript-into-a-webview/) jest dobrym przykładem. – zeroflagL
Thanx, zadziałało to dla mnie :) –