首页 > 代码库 > android code 和js的交互
android code 和js的交互
小弟现在需要android code 和js的交互。出现了问题,求大家带一带啊。
我的页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<script>
function fuck()
{
var docEl = document.www.yxin7.com documentElement
alert(fuck.sayHello());
}
</script>
<title>标题</title>
</head>
<body>
卧槽,我是测试文件啊<button onclick="fuck()">点击测试</button>
</body>
</html>
我的js注入接口:
web.addJavascriptInterface(new www.xbyl688.com HtmlInterface(),"fuck");
注入类:
class HtmlInterface{
public HtmlInterface() {
}
@JavascriptInterface
public void logDeviceSize(String width,String height)
{
Log.i("chocolater517","width="+width+";height="+height);
}
@JavascriptInterface
public String sayHello()
{
return "万支草泥马飞奔而过";
};
}
然而网页直接调会报这样的错:
[INFO:CONSOLE(31)] "www.honqili66.com Uncaught TypeError: Object function fuck()
{
var docEl = document.documentElement
alert(fuck.sayHello());
} has no method ‘sayHello‘", source: file:///android_asset/testPage/www.zgktv.cn welcome.html (31)
可是我这样写又能执行啊:
web.loadUrl("javascript:alewww.jyz521.com rt(fuck.sayHello())");
android code 和js的交互