Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a web page determine if/when something is viewed?

I'm seeking to understand the code and function(s) that determines when a particular part of a webpage has been viewed (for mere understanding).

For example, on the Stack Exchange web sites, it determines when a person has fully read the "about" page (and awards a badge for such). What function/code/language is watching for this?

Or at least, how could I trace and/or determine where this function is in a page's source?

like image 255
Coldblackice Avatar asked Jan 31 '26 16:01

Coldblackice


1 Answers

You can use JavaScript to detect how far a user has scrolled on the page, and if they've scrolled past a certain point (say 80% of the article) you can fire off an AJAX request which logs that the user has scrolled past that point.

Quick example in jQuery:

$('body').scroll(function () {
    if($(this).scrollTop() > 1000) {
        // Fire off AJAX request
    }
});

Didn't test that, and you'll want to change 1000 to be the amount of pixels until you get to an element in the article so it works for different article lengths.

like image 151
James Dawson Avatar answered Feb 02 '26 06:02

James Dawson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!