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 6371861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:08:46+00:00 2026-05-25T01:08:46+00:00

Is it possible to tell whether a scroll event was done by the browser

  • 0

Is it possible to tell whether a scroll event was done by the browser or by the user? Specifically, when using the back button a browser may jump to the last known scroll position. If I bind to scroll event how can I tell whether this was caused by user or browser?

$(document).scroll( function(){ 
    //who did this?!
});

I see three types of situations that cause scrolling in a browser.

  1. The user performs some action. For example, uses mousewheel, arrow keys, page up/down keys, home/end keys, clicks the scrollbar or drags its thumb.
  2. The browser scrolls automatically. For example, when using the back button in your browser it will jump to the last known scroll position automatically.
  3. Javascript scrolls. For example, element.scrollTo(x,y).
  • 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-25T01:08:47+00:00Added an answer on May 25, 2026 at 1:08 am

    Unfortunately, there is no direct way of telling that.

    I would say if you can redesign your app so that it doesn’t depend on this type of flow, go for that.

    If not, a workaround I can think of is to keep track of user initiated scrolls and check that to see if the scroll was triggered by the browser or by the user.

    Here’s an example that I put together which does this pretty well (except for browsers where jQuery history has problems with).

    You need to run this locally to be able to test it fully (jsFiddle/jsbin are not good fits as they iFrame the contents).

    Here’s the test cases that I validated:

    • Page loads – userScroll is false
    • Scroll using mouse/keyboard – userScroll becomes true
    • Click on the link to jump to page bottom – userScroll becomes false
    • Click Back/Forward – userScroll becomes false;

    <!DOCTYPE html> 
    <html lang="en"> 
    <head> 
        <meta charset="utf-8" /> 
        <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script> 
        <script type="text/javascript" src="https://raw.github.com/tkyk/jquery-history-plugin/master/jquery.history.js"></script> 
    </head> 
    <body> 
        <span> hello there </span><br/> 
        <a href="#bottom"> click here to go down </a> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        <a name="bottom"> just sitting </a> 
    </body> 
    <script type="text/javascript"> 
    
    var userScroll = false;     
    
    function mouseEvent(e) { 
        userScroll = true; 
    } 
    
    
    $(function() { 
    
        // reset flag on back/forward 
        $.history.init(function(hash){ 
            userScroll = false; 
        }); 
    
        $(document).keydown(function(e) { 
            if(e.which == 33        // page up 
               || e.which == 34     // page dn 
               || e.which == 32     // spacebar
               || e.which == 38     // up 
               || e.which == 40     // down 
               || (e.ctrlKey && e.which == 36)     // ctrl + home 
               || (e.ctrlKey && e.which == 35)     // ctrl + end 
              ) { 
                userScroll = true; 
            } 
        }); 
    
        // detect user scroll through mouse
        // Mozilla/Webkit 
        if(window.addEventListener) {
            document.addEventListener('DOMMouseScroll', mouseEvent, false); 
        }
    
        //for IE/OPERA etc 
        document.onmousewheel = mouseEvent; 
    
    
        // to reset flag when named anchors are clicked
        $('a[href*=#]').click(function() { 
            userScroll = false;
        }); 
    
          // detect browser/user scroll
        $(document).scroll( function(){  
            console.log('Scroll initiated by ' + (userScroll == true ? "user" : "browser"));
        });
    }); 
    </script> 
    </html>
    

    Notes:

    • This doesn’t track scrolling when the user drags the scrollbar with mouse. This can be added with some more code, which I left as an exercise for you.
    • event.keyCodes may vary by OS, so you may have to change that appropriately.

    Hope this helps!

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

Sidebar

Related Questions

Please tell me whether it is possible to use both SimpleUrlHandlerMapping and AnnotationMapping in
I understand that it is not possible to tell what the user is doing
Is it possible to tell whether a node is contained within (or equal to)
Is it possible to tell whether a stash has already been applied, and therefore
Possible Duplicate: How to tell whether I’m static or an object? Let's say I
Is it possible to tell the C preprocessor to check whether a function (not
Is it possible to tell from inside a page constructor whether OnNavigatedTo will be
My question is is it possible to tell from an UIEvent object whether it
Is there a simple way to tell what triggered Click event of a Button
Possible Duplicate: How can I tell whether an element matches a selector? I've been

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.