I have hosted a web project in my system.I need to run the html content in Android application using WebView. I did that.My requirement is I need to get the content of the html page or Javascript inside it, in my activity.I sit possible.Please help me.
My html page contains one checkbox and some content inside
. I also have Save button. When I click the开发者_StackOverflow中文版 Save button I should get the content of the hidden fields inside the html page in My Activity .IS that possible. pls help me.Finally I got the problem resolved.. In my activity I added a JavaScript interface with a javascript function named saved() in it.In my html page I added a javascript function named clicked().In this function I collected all the values as a String and passed to the saved(). The saved() function is in my activity and so I could use the values in my Activity.
In Oncreate()
{
mWebView.addJavascriptInterface(new DemoJavaScript(),"demo");
mWebView.loadUrl("file:///android_asset/index.html");
}
final class DemoJavaScript {
DemoJavaScript() {
}
// This is the javascript function
public void saved(String values) {
Toast.makeText(getApplicationContext(), values, Toast.LENGTH_SHORT).show();
}
}
// my html page
<script language="JavaScript">
var values;
function clicked()
{
values="";
values=document.getElementById('myvalue');
window.demo.saved(values);
}
</script>
<body>
<br />
<input type="hidden" name="myvalue" id="myvalue" value="reebok"/>
<br/>
<table>
<tr><td width="100" align=right><input type="button" name="save" value="Save" onClick="clicked()"/></td><td><input type="button" name="cancel" align=center value="Cancel"/></td></tr>
</table>
</body>
</html>
精彩评论