WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
myWebView.loadUrl("file:///android_asset/index.html");
myWebView.loadUrl("javascript:hello()");
It doesnt work in 4.0 emulator or real device. I have proper tag in html like
<script type="text/javascript">..</script>
and i can fire it from firefox’s console with no problem (it doesnt call alert command, i know it doesnt work in android)
I am out of solutions, please help me.
Btw this function call seems useless here because it is for testing, i will give a parameter later if this works.
Edit:
<h1 id="title"></h1>
....
<script type="text/javascript">
function hello()
{
console.log("hello");
var title = document.getElementById("title");
title.innerHTML = "hello";
}
</script>
The problem is that there is no guarantee that the page has been loaded when you call the javascript. Make sure that you call the javascript function only when the page is completely loaded.
The following code (quoted from http://lexandera.com/2009/01/injecting-javascript-into-a-webview/) will give you a heads up.