I have an Android webview with a page that redirects to another page, using location.replace(url)
.
Lets say that I have page "A" that redirects to page "B" (using location.replace). When pressing "back" button from page "B", the page returns to page "A", which redirects it to page "B" again.
When I debug the history api (history.length), I can clearly see that on page "B" the length has incremented in "1" (only on Android 4.X webview. On iOS / web browser / Android 2.X it remains the same), which is a bug! (location.replace shouldn't change history.lenght!)
相关问题
- Is there a limit to how many levels you can nest i
- How can I create this custom Bottom Navigation on
- How to toggle on Order in ReactJS
- Bottom Navigation View gets Shrink Down
- void before promise syntax
Try this way..
Or get help from this and this link
I work with Yaniv on this project and we found the cause of the problem, it was introduced when we tried to add
mailto:
links handling according to this answer.The answer suggested using the following extending class of WebViewClient:
The problem was that explicitly telling the
WebViewClient
to load the URL and returning true (meaning "we handled this") added the page to the history. WebViews are quite capable of handling regular URLs by themselves, so returning false and not touching the view instance will let the WebView load the page and handle it as it should.So: