In a WebView is there a way for shouldOverrideUrlLoading to determine if it is catching a redirect vs. a user clicking a link?

前端 未结 6 586
时光说笑
时光说笑 2021-02-01 06:06

I would like to allow redirects to happen naturally in the WebView and only catch a new url if it is a happening because a user clicked something.

6条回答
  •  暖寄归人
    2021-02-01 06:45

    Not directly, no.

    You can use a combination of WebViewClient.onPageStarted and WebView.getOriginalUrl to try to determine if the url being display is the original one requested, but this is after the WebView has decided to load the Url. This can help determine if a redirect has happened but still won't distinguish between user events and script events that do not cause redirects.

    If you control the content of the web content, you could also encode the user-clickable Urls in some identifiable way (eg. a proprietary scheme instead of http) and do any additional processing that you require if the criteria match in your shouldOverrideUrlLoading implementation.

提交回复
热议问题