Android的WebViewClient,onErrorReceived不会被调用时,有一个404有一个、WebViewClient、Android、onErrorReceived

2023-09-08 09:19:23 作者:拳拳杀气

我有一个web视图,以WebViewClient定义onErrorReceived和onPageFinished。

I've got a WebView, with a WebViewClient that defines onErrorReceived, and onPageFinished.

在onPageFinished被调用正确的,所以我知道WebViewclient是否正确连接到的WebView。然而,有一个在web视图一些JavaScript调用:

The onPageFinished gets called correctly, so I know that the WebViewclient is attached to the WebView correctly. However, there's some javascript in the WebView that calls:

location.href =htt​​p://kernel.org/asdf/asdf/asdf/asdf;

而onErrorReceived听者不叫,即使它是一个404这岂不是用JavaScript调用工作?

And the onErrorReceived listener is not called, even though it's a 404. Does it not work with javascript calls?

编辑:经过一些测试,我发现没有404报告给这个函数任何责任。我有一个测试项目设在这里: http://vimtips.org/media/WebViewTest.zip

After some testing, I have found that NO 404s are reported to this function whatsoever. I have a test project set up here: http://vimtips.org/media/WebViewTest.zip

似乎这种方法不能用于测试404。任何人都知道的一种方式做到这一点?

It appears that this method cannot be used to test for 404s. Anyone know of a way to do this?

推荐答案

它不能这样做。至少,不是在非哈克方式

It can't be done. At least, not in a non-hacky way.