Klaas Leussink
Klaas Leussink

Reputation: 2737

Mobile Safari: JS event for jump to last scroll position on refresh

Is there a Javascript event that I can hook into that fires when the page is refreshed, and Safari 'jumps' back to the scroll position you were at?

It's very frustrating, as the scroll event only fires on user/touch-induced scrolls, so will not fire in this case. I need to specifically find a way to bind to that event, as DOMContentLoaded, for example, fires even before that, and the window's load event would fire too late, as that will wait for all content to load.

Reason for this is that I am checking if an element is in view (using getBoundingClientRect).

Am I missing something here? As I'm not using jQuery, but vanilla JS, I have no document.ready() to try (though judging by the source code of it, I doubt it would work).

Upvotes: 1

Views: 659

Answers (1)

Klaas Leussink
Klaas Leussink

Reputation: 2737

After some experimenting, it turns out that the load /onload event on the window triggers this jump in Safari Mobile (and presumably other browsers too), so binding to that event would suffice.

I hope this helps someone!

Upvotes: 1

Related Questions