目录

What should I do if accessBackward of Webview does not meet expectations?

Symptom

Generally, when a new page is redirected, the forward and backward stacks increase. In this case, accessBackward returns true, indicating that there are backward history nodes. However, in some cases, the new redirection does not add a historical node but replaces the current node. For example, when the same URL is loaded, or when the initial URL is refreshed during loading.

Scenario 1: The accessBackward does not meet expectations due to incorrect reload.

Solution

During the initial URL loading, if the page is refreshed, for example, by calling refresh or automatically refreshing the page by calling setCustomUserAgent, the forward and backward stacks in the web component remain the initial node. In this case, the subsequent redirection replaces the initial node, and no historical node is added. accessBackward returns false.

If setCustomUserAgent is called during page loading, the page is automatically refreshed. For details about how to use setCustomUserAgent, see setCustomUserAgent.

Scenario 2: The accessBackward does not match expectations due to the historical operation intervention mechanism.

Solution

Some pages are redirected or operated on the browser history, which makes it impossible or difficult for users to return to the previous page using backward. This affects user experience. The history operation intervention mechanism alleviates this issue by bypassing history entries or redirecting pages that are added without user activation. Note that this intervention affects only the backward and forward operations of the browser but does not affect the front-end history.back() and history.forward().

Example:

  1. A user accesses the website a.com and clicks to go to the website b.com.
  2. b.com uses pushState to add a history entry, or navigates the user to another page (c.com) without user activation.
  3. If the user presses the back button, the system skips b.com and directly returns to a.com.