I have a busy webpage with lots of widgets. It takes a second or two to load sometimes.
When I hit refresh from some location other than the top of the page, I can see that the page loads as if scrollTop==0
and at some point snaps back to my original position.
The problem is that I have various initializations that occur in a .ready()
event handler, some of which rely on scrollTop
and scrollLeft
. These initializations occur before the document has returned to it's original position, which then give nonsensical results from the original position.
Wrapping these initializations inside a .load()
event handler doesn't seem to work, either. What does work is adding a (fairly long) delay via setTimeout inside the .load()
handler. This is undesirable for obvious reasons.
This suggests that the "return to original position" happens independently of the standard event chains, ie. is not specified in the ECMA standards or is browser-implementation dependent.
What is the best way to deal with initializations that need to happen only after the browser has returned to the original position? Is there an associated event? Is there some way to recognize that a refresh has occurred and only delay in that case?
All of my testing has been in Chrome and Firefox.