[英]shouldOverrideUrlLoading does not work/catch link clicks while page is loading
I am using WebViewClient.shouldOverrideUrlLoading to catch any link clicks in the WebView. 我正在使用WebViewClient.shouldOverrideUrlLoading来捕获WebView中的任何链接点击。 This works about 95% of the time, but sometimes it is simply not called.
这大约有95%的时间都有效,但有时它根本就没有被调用。
I have noticed it in these three circumstances: 我在这三种情况下都注意到了这一点:
shouldOverrideUrlLoading
. shouldOverrideUrlLoading
情况下打开链接。 Now my question is mostly how to fix problem 2, since the others are less of a big deal. 现在我的问题主要是如何解决问题2,因为其他问题不是很重要。 However, if someone has solved either 1 or 3 I would love to hear about it.
但是,如果有人解决了1或3,我很乐意听到它。
Also, I should mention that I have tried different return values in shouldOverrideUrlLoading
and I have noticed that always returning true seems to have the best result, but the issues above still happen. 另外,我应该提一下,我在
shouldOverrideUrlLoading
尝试了不同的返回值,我注意到总是返回true似乎有最好的结果,但上面的问题仍然会发生。
If the HTML is your own, you can replace all traditional links with calls to your own Java object, injected into the WebView
via addJavascriptInterface()
. 如果HTML是您自己的,您可以使用对自己的Java对象的调用替换所有传统链接,通过
addJavascriptInterface()
注入WebView
。 Then you will no longer be reliant upon shouldOverrideUrlLoading()
. 然后你将不再依赖于
shouldOverrideUrlLoading()
。
Otherwise, perhaps try to prevent the user from interacting with the page until onPageFinished()
. 否则,可能会尝试阻止用户与
onPageFinished()
交互。
I have not run into this problem, but I have not made extensive use of WebView
with arbitrary content, either. 我没有遇到过这个问题,但我还没有广泛使用带有任意内容的
WebView
。
I've had a similar issue when trying to change the webpage with js on the page that modifies window.location
. 尝试使用修改
window.location
的页面上的js更改网页时,我遇到了类似的问题。 Turns out that modifying the url scheme/protocol makes the webview catch on shouldOverrideUrlLoading
. 事实证明,修改url scheme / protocol会使webview捕获
shouldOverrideUrlLoading
。 I know this doesn't help you since you don't own the HTML, but I thought it would help anyone else who stumbles upon this problem. 我知道这不会帮助你,因为你没有HTML,但我认为它会帮助其他任何偶然发现这个问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.