`window.pageYOffset` is wrongly reported as `0` until well after window load event when the browser itself has restored scroll position, such as from back button or reload

Confirmed Issue #9453934 • Assigned to James M.

Details

Author
Dennis H.
Created
Oct 21, 2016
Privacy
This issue is public.
Found in
  • Microsoft Edge
  • Internet Explorer
Reports
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

I created a minimal test case:
https://dennishall1.github.io/pageYOffset-test/
Just scroll down a bit and then hit refresh. The test will tell you if it passes or fails.
Close and reopen your browser, or just clear cache, to try it again (it uses sessionStorage).

This affects parallaxing websites, websites that do things with content based on scroll position. There are plenty of valid use-cases. Unfortunately, IE reports pageYOffset as 0 all the way up to, including, and just after the window load event. Chrome, Firefox, and Safari correctly report the window scroll position at all times. Because IE doesn’t report the correct value until very late in the page render flow, I have to put a setTimeout inside of the window load event, and users in IE experience a jump, and generally, correctly, believe that their browser is the culprit.

if(msie){
    // ie...
    window.addEventListener('load', () => {
        window.setTimeout(() => {
            this.accountForInitialPageScroll();
        }, 500);
    })
} else {
    // everyone else
    this.accountForInitialPageScroll();
}

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Brad E.”

      Changed Status to “Confirmed”

      Changed Assigned To from “Brad E.” to “James M.”

    You need to sign in to your Microsoft account to add a comment.

    Sign in