RESOLVED INVALID 262542
history.back() does not restore scroll position
https://bugs.webkit.org/show_bug.cgi?id=262542
Summary history.back() does not restore scroll position
Christian Taylor
Reported 2023-10-03 08:04:56 PDT
When navigating back to a long page using `history.back()` or `history.go(-1)` the browser returns to the page and resets the scroll position to `0`. However, performing the same navigation using the browser's "back" button restores the scroll position on the previous page. I would expect `history.back()` to behave the same as clicking the back button and restore the previous page's scroll position.
Attachments
Simon Fraser (smfr)
Comment 1 2023-10-03 10:29:25 PDT
Do you have an example of a page that shows this bug?
Radar WebKit Bug Importer
Comment 2 2023-10-03 10:29:37 PDT
Christian Taylor
Comment 3 2023-10-03 11:25:55 PDT
Ah, I put together a demo and found an explanation. My link markup looked like this: `<a href="/previous" onclick="history.back()">Back</a>` I realized `back()` is asynchronous so the `href` is being followed as though the link were clicked. If I change the `onclick` to `event.preventDefault();history.back()` things work as I would expect. I was thrown off because `onclick="history.back()"` works in FireFox without needing the `preventDefault()`. I think this report can be closed. Thanks for letting me rubber duck this issue.
Simon Fraser (smfr)
Comment 4 2023-10-03 11:39:35 PDT
Thank you for checking.
Note You need to log in before you can comment on or make changes to this bug.