android的webview调用javascript函数并得到返回值
java代码:
?
ProxyBridge pBridge = new ProxyBridge(); wv.addJavascriptInterface(pBridge, "test"); loadurl(wv, "file://sdcard/test/cookie.html");private class ProxyBridge {public void getCookie(String name,String value) {
System.err.println("哈哈哈,成功了:"+name+" "+value);}}
?
html代码
function getCookie(name)//取cookies函数 { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null){test.getCookie(name,unescape(arr[2]));
}else{
test.getCookie(name,"null"); }}
?