I have a gallery website with paintings that scrolls from left to right with overflow-x: scroll
.
When the user clicks on a painting, the current scroll position is stored in localStorage
and the detail page is shown. When the user clicks the back button, the scroll position is being set when the page is loaded.
I want this scroll position to be unset when the page is being loaded in a new tab or window. How can I tell if this happened?
Unsetting on page reload is already working. But opening the website in a new window does not count as a reload apparently.
I have tried reading the sessionStorage
, but that doesn't do the trick.
if (performance.navigation.type == 1 || sessionStorage.isNewSession) {
localStorage.setItem("scrollPositionHome", 0);
}
performance.navigation.type
sees it's a page reload, sessionStorage.isNewSession
isn't doing much.