javascript in html been using in android
I have this url for the school timetable search, but all the result and the search page are using the same url, and the main body is running by the javascript in side the html.
the url is http://epoly.tp.edu.sg/tpapp/isistt/TTServlet
so how can I get the search re开发者_开发百科sult in android? the javascript from the source code is
function change(dropdownvalue)
{
document.form1.txtAction.value='ChangeSearch';
submitForm('form1', 'TTServlet');
}
function getTT (action, staffid)
{
document.form1.txtAction.value=action;
document.form1.txtSelStaffID.value=staffid;
submitForm('form1', 'TTServlet');
}
function search (action)
{
if (validate())
{
document.form1.txtAction.value=action;
submitForm('form1', 'TTServlet');
}
}
function validate()
{
if (trim(document.form1.txtStaffID.value)== '' && trim(document.form1.txtStaffName.value)== '')
{
document.form1.txtStaffID.focus();
alert("Please enter a search value for either Employee ID. or Staff Name.");
return(false);
}
return (true);
}
function clearFields()
{
document.form1.txtStaffID.value='';
document.form1.txtStaffName.value='';
}
Use addJavaScriptInterface
to have a binding between JavaScript and Android
From Android,
WebView webView;
webView.loadUrl("http://epoly.tp.edu.sg/tpapp/isistt/TTServlet");
// Add JS libraries
webView.addJavascriptInterface(new TTSearch(), "TimeTable");
private class TTSearch{
public void SearchResult(String result) // This function is called from JavaScript
{
Log.v(LOGTAG, "Search Result is - " + result);
}
}
From Javascript,
var a = result; //your result which you intend to send to android
TimeTable.SearchResult(a);
精彩评论