将信息JavaScript发送到Android(webview)
我的源代码有问题, 我已经编写了一个javascript函数,我用一个简单的按钮将其激活到HTML页面中 代码如下所示:将信息JavaScript发送到Android(webview),javascript,android,Javascript,Android,我的源代码有问题, 我已经编写了一个javascript函数,我用一个简单的按钮将其激活到HTML页面中 代码如下所示: <html> <head> <base href="http://localhost:8080/testAndroidReturn/" target="_blank"> </head> <body> <div class="col-md-6 col-md-
<html>
<head>
<base href="http://localhost:8080/testAndroidReturn/" target="_blank">
</head>
<body>
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-title">
<h4>teste android</h4>
</div>
</div>
<div class="panel-body">
<input type="text" id="text" value="" />
<button type="submit" onclick="saveText()"> submit </button>
</div>
</div>
</div>
<script type="text/javascript">
function saveText(){
alert("coucou");
AndroidFunction.showToast("COUCOU");
}
</script>
</body>
</html>
但当我启动android应用程序并点击按钮中的WebView
时,它什么也不做,我的日志中出现了以下错误消息:
04-16 04:24:14.458 1212-1212/com.bepark.myapplication.app I/Choreographer﹕ Skipped 148 frames! The application may be doing too much work on its main thread.
04-16 04:24:14.578 1212-1212/com.bepark.myapplication.app I/chromium﹕ [INFO:CONSOLE(22)] "Uncaught TypeError: Object [object Object] has no method 'showToast'", source: http://10.10.202.184:8080/testAndroidReturn/ (22)
我不明白为什么?如果您的目标是Jelly Bean操作系统,请尝试将注释
@JavascriptInterface
添加到您的公共方法中
希望这能有所帮助。如果您的目标是Jelly Bean操作系统,请尝试将注释
@JavascriptInterface
添加到您的公共方法中
希望有帮助
04-16 04:24:14.458 1212-1212/com.bepark.myapplication.app I/Choreographer﹕ Skipped 148 frames! The application may be doing too much work on its main thread.
04-16 04:24:14.578 1212-1212/com.bepark.myapplication.app I/chromium﹕ [INFO:CONSOLE(22)] "Uncaught TypeError: Object [object Object] has no method 'showToast'", source: http://10.10.202.184:8080/testAndroidReturn/ (22)