我已经尝试将参数从javascript传递到android但它返回
01-08 20:32:17.214: D/WebConsole(27791): Uncaught Error: Error calling method on NPObject. -- From line 433 of file:///data/data/com.test/files/HK/news_list.html
我的代码如下
JS:
function changeSection(){
//var pos = parseInt($(this).attr("data-index"),10);
var pos = 2;
if (pos == 3){
window.location.href="video_list.html";
} else {
window.location.href="news_list.html?target="+$(this).attr("target")+"&type="+$(this).attr("type");
}
window.jsinterface.highLightLeftMenu(2);
}
构建按钮链接的代码:
if(target+'_'+pageType == LMenu[k]['sid']){
sectionMenu += "<div class='focus' data-index='"+k+"' target='"+tmpArr[0]+"' type='"+tmpArr[1]+"' onclick=\"changeSection()\">"+LMenu[k]['name']+"</div>";
}else{
sectionMenu += "<div data-index='"+k+"' onclick=\"changeSection()\">"+LMenu[k]['name']+"</div>";
}
机器人:
mWebView.addJavascriptInterface(this, "jsinterface");
public void highLightLeftMenu(int pos) {
Log.d("test1","aa");
Log.d("test1","bb" + pos);
MainActivity.highLightLeftMenu(pos);
}
它可以在android中注销aa和bb与pos,但是在webview中返回错误信息,还有,如何将js / jquery中的整数传递给android而不需要硬编码?感谢