在WebView中侦听URL片段ID的更改 [英] Listen for URL fragment id change in WebView

查看:151
本文介绍了在WebView中侦听URL片段ID的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎WebViewClient方法(例如shouldInterceptRequest(),onPageStarted()和ShouldOverrideUrlLoading())仅侦听导致WebView加载新页面的URL更改.是否可以检测WebView上片段ID(即index.html#fragment_id)的URL更改?

It seems that the WebViewClient methods such as shouldInterceptRequest(), onPageStarted(), and shouldOverrideUrlLoading() only listen for URL changes that cause the WebView to load a new page. Is there a way to detect URL changes for fragment IDs, i.e. index.html#fragment_id, on a WebView?

推荐答案

正如mitvenkatesan在对该问题的评论中所述,可以通过覆盖WebView内部页面的window.onhashchange()事件来实现.

As mitvenkatesan described in his comment to the question, this can be achieved by overriding the window.onhashchange() event of the page inside the WebView.

事实证明,此解决方案已在另一个问题中得到解决.

It turns out that this solution has already been addressed in another question.

这篇关于在WebView中侦听URL片段ID的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆