一、Java代码
1、webView的设置
webView.getSettings().setDefaultTextEncodingName("utf-8");
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://shaoml.oicp.net/mt_app_int/weixin/around.jsp?mobile=" + phone + "&token=" + token);
// WebChromeClient主要辅助WebView处理Javascript的对话框、网站图标、网站title、加载进度等
// webChromeClient = new WebChromeClient() {
// @Override
// public void onReceivedTitle(WebView view, String title) {
// super.onReceivedTitle(view, title);
// // tv_title_content.setText(title);
// SunriseUIHelper.showTip(Around_Activity.this, "当前页面Title:" + title);
// wv_list.getSettings().setJavaScriptEnabled(true);
// }
// };
// wv_list.setWebChromeClient(webChromeClient);
webView_list.addJavascriptInterface(this, "todetail");
/**
*
*按返回的html地址跳转页面
*html路径要是绝对路径
* @param year
*/
@JavascriptInterface
public void refresh(String html, String name) {// 跳转到商家详情页面
Intent adetailIntent = new Intent(Around_Activity.this, Around_Detail_Activity.class);
adetailIntent.putExtra("html", "http://shaoml.oicp.net/mt_app_int/weixin/" + html);
adetailIntent.putExtra("name", name);
startActivity(adetailIntent);
}
二、Js代码
(1)直接传
window.todetail.refresh(‘http://mob.com‘,"全家");
(2)当变量传
getShopUrl = function(obj){
var sellerid = $(obj).parent().attr("sellerid");
var url = "\aroundInfo.jsp?sellerid="+sellerid;
var sellerTitle = $(obj).children(".aroundLi").children(".aroundLiTit").html();
if(window.todetail != undefined){
//要记得加上“”,这样java那边才知道是字符串类型,才能做对应的操作。
window.todetail.refresh(url+"",sellerTitle+"");
}else{
location.href=url;
}
};