Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:53:07+00:00 2026-05-14T02:53:07+00:00

I know how to get the scrollTop of a page, I use this simple

  • 0

I know how to get the scrollTop of a page, I use this simple JS function (code copied around):

function GetScrolledTop() 
{
   //I never work in IE quirkmode, I always use DOCTYPE as 1st line, so I don't need to test for document.body.scrollTop
   return self['pageYOffset'] || document.documentElement.scrollTop; 
}

This works and my problem is the following: I tried to add it in the page onload event

<body onload="alert(GetScrolledTop());">

On page load I get ZERO (which make sense), but the problem is that I get ZERO even if I scroll the page and then reload it without touching the scrollbar.

It seems like the browser does:

  1. loads page
  2. calls my GetScrolledTop() (so obviously shows ZERO)
  3. then scrolls the page to where it was before.

Do you know how to get the scolledTop after the step 3?
I mean how to get the scrolledTop AFTER the browser scrolled the page?
(maybe without using a timer)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:53:08+00:00Added an answer on May 14, 2026 at 2:53 am

    Probably not without using a timer. But you might be able to use a timer with a 0ms delay, which would execute the function when the thread becomes idle, whilst still appearing to be instant:

    <body onload="window.setTimeout(function () { alert(GetScrolledTop()); } , 0);">
    

    EDIT – Thought it might also be worth mentioning that most browsers support the onscroll event, which should fire after the window scrolls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know if there's some way to get: $('html,body').animate({scrollTop: +=1800px},2000); but with
the two ways that I know to get the page url are: 1.through the
I just don't know how to solve this altough it's probably fairly simple. I
I can't get Facebook Javascript functions to work inside of certain jQuery commands... This
I'm trying to use this function for infinite scroll: <script type=text/javascript charset=utf-8> (function() {
I am using Nokogiri to analyze some HTML, but, I don't know how get
I know how to get a current date. but I want it to display
I know how to get the latest source from GIT which is version 7.1.2
I know how to get a string from another string, but only if it's
I know I can get touch events in my iPhone app. But these touch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.