WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: Meaningful Sequence in SPAs

for

From: Dean.Vasile@outlook.com
Date: Apr 16, 2024 10:58AM


In an old-school website with multiple .html pages, when a user clicks the browser's back button, the behavior primarily involves navigating back to the previous page, similar to following a link to that page. However, the restoration of focus—the specific element that was last focused before navigating away—is not consistently handled across different browsers and can depend on several factors.Here’s how it generally works:Navigation: The back button primarily causes the browser to navigate to the previous URL in its history stack. This means that the browser loads the previously visited page either from cache or by making a new request to the server.Restoration of State: Most modern browsers attempt to save the state of the previous page including the scroll position and sometimes form inputs. However, whether focus is restored to the last focused element before navigating away is less consistently managed.Focus Behavior: The restoration of focus is not guaranteed and can behave differently across different browsers. In many cases, when navigating back:The focus might start at the beginning of the document rather than on the last focused element.Some browsers might maintain focus on the same element if the page is retrieved from the cache (bfcache or Back/Forward Cache, for instance), but this is not universally reliable.Standards and Practices: There isn't a strict standard requiring browsers to restore focus to the last focused element when navigating back. This behavior is largely up to the implementation by the browser developers, and can vary:Google Chrome: Typically does not restore focus to the last active element after navigating back.Mozilla Firefox: Similar to Chrome, it generally does not restore focus to the previously active element.Safari: Might exhibit slightly different behaviors, especially on iOS, but generally aligns with Chrome and Firefox in this respect.Therefore, if maintaining focus is crucial for your website's usability, especially across page navigations, it might be necessary to implement a custom solution. This can involve using JavaScript to remember the last focused element before the page unloads and then restoring that focus when the page is loaded again (assuming the page is revisited via the back button). This approach, however, requires careful programming to ensure compatibility and performance across different browsers and devices.
Dean Vasile


617-799-1162

> On Apr 16, 2024, at 12:15 PM, Brian Lovely < <EMAIL REMOVED> > wrote:
>
> In an old-school website with multiple .html pages, does the browser back
> button restore focus, or does it simply navigate to the previous page same
> as any link would?