简体   繁体   English

当页面加载时,shouldOverrideUrlLoading不起作用/捕获链接点击

[英]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: 我在这三种情况下都注意到了这一点:

  1. When the link points to the page they are already on. 当链接指向他们已经在的页面时。 This one isn't a really big deal, and there is a bug reported for it . 这个并不是什么大问题,并且报告了一个错误
  2. While the page is still loading, if the user clicks a link, it rarely catches it. 当页面仍在加载时,如果用户单击链接,则很少捕获该链接。 It will just open the link without ever calling shouldOverrideUrlLoading . 它只会在没有调用shouldOverrideUrlLoading情况下打开链接。
  3. Randomly. 随机。 While experimenting with this over the last couple months I have noticed that sometimes it just doesn't catch it. 在过去几个月的实验中,我注意到有时它只是没有抓住它。 It is rare but it does happen. 这种情况很少见,但确实发生了。

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.

相关问题 使用WebViewClient shouldOverrideUrlLoading时,WebChromeClient中的链接不会打开野生动物园 - Link in WebChromeClient does not open safari when using WebViewClient shouldOverrideUrlLoading 在shouldOverrideUrlLoading中未捕获重定向 - Doesn't catch redirect in shouldOverrideUrlLoading 用户在Facebook登录页面加载时点击任意位置的回调问题 - callback issue in Facebook while user clicks anywhere while Facebook login page is loading Android WebView不会在链接单击时启动标准浏览器-ShouldOverrideUrlLoading无效 - Android WebView does not start standard browser on link click - shouldOverrideUrlLoading has no effect WebViewClient不会打开在ShouldOverrideUrlLoading()中处理的页面 - WebViewClient will not open page handled in shouldOverrideUrlLoading() Webview应该覆盖URL加载不起作用 - Webview shouldoverrideurlloading doesn't work shouldOverrideUrlLoading 在 SDK 版本 &lt; 18 上加载内部和外部 - shouldOverrideUrlLoading loading internally and externally on SDK versions < 18 Android - webview - shouldOverrideUrlLoading未调用 - 当用户点击iframe内的链接时 - Android - webview - shouldOverrideUrlLoading not called - when user clicks links inside iframe 无法获取shouldOverrideUrlLoading以在Android应用中工作 - Cannot get shouldOverrideUrlLoading to work in Android app 使用RxView.clicks(订阅无效) - Use RxView.clicks (subscribe does not work)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM