0

我有一个 webview 并且 javascript 界面也在那里。如何为其添加 window.onerror ?主要要求是,当我加载带有内容的 webview 时,otf 文件会引发一些无效标签错误(“OTS 解析错误:无效版本标签”),我需要捕获该错误。

4

1 回答 1

0

当您收到错误时,您可以从 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 +" )");
}
于 2017-05-11T17:22:36.220 回答