android webview javascript 调用缺少的函数
我需要从 android 的 webview 调用 javascript 时捕获错误;如果缺少 javascript,我需要捕获一些事件并在 android 中执行其他操作。
例如,我有 webview.loadUrl("javascript:doSomething");
该页面缺少“doSomething”,因此我可以在 logcat 中看到以下错误:
ReferenceError: Can't find variable: doSomething ...
我需要捕获此错误并处理它,例如类似
public override void onJsErrorReceived(String errorDescription)
{
if(errorDescription.contains("doSomething"))
handleError();
}
I can't find any这样的事件在 webview 中,也不能在 webview 的客户端(WebChromeClient 和 WebViewClient)中重写。
有人有想法吗?
谢谢
I need to catch an error when invoking javascript from android's webview; if the javascript is missing I need to catch some event and do something else in android instead.
for instance, I have webview.loadUrl("javascript:doSomething");
the page is missing 'doSomething', so I can see the following error in logcat:
ReferenceError: Can't find variable: doSomething ...
I need to catch this error and handle it, for instance something like
public override void onJsErrorReceived(String errorDescription)
{
if(errorDescription.contains("doSomething"))
handleError();
}
I can't find any such event in webview, nor in the clients of webview (WebChromeClient and WebViewClient) to overridel.
Does anybody have an idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据这个问题,您需要重写的方法是:
WebChromeClient.onConsoleMessage(String message, int lineNumber, String sourceID)
和
WebChromeClient.onConsoleMessage(ConsoleMessage cm)
,As per this question, the methods you need to over-ride are:
WebChromeClient.onConsoleMessage(String message, int lineNumber, String sourceID)
and
WebChromeClient.onConsoleMessage(ConsoleMessage cm)
,