我有一个webview,javascript界面也在那里。如何为其添加 window.onerror?主要要求是,当我加载包含内容的 Web 视图时,otf 文件会抛出一些无效的标记错误("OTS 解析错误:无效的版本标记"(,我需要捕获该错误。
当你收到错误时,你可以从 Java 调用一个 JavaScript 函数:
/**
* Executes received Java Script call
*
* @param command - JS call to run
*/
protected void executeJsCommand(final String command) {
webView.evaluateJavascript(command, new ValueCallback<String>() {
@Override
public void onReceiveValue(final String value) {}
});
}
protected void callOnError(String error) {
executeJsCommand("window.onerror( " + error +" )");
}