简体   繁体   English

网页如何确定是否/何时查看某些内容?

[英]How does a webpage 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 StackExchange websites, it determines when a person has fully read the "about" page (and awards a badge for such). 例如,在StackExchange网站上,它确定一个人何时完全阅读“关于”页面(并为此授予徽章)。 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? 或者至少,我如何跟踪和/或确定此功能在页面源中的位置?

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. 您可以使用JavaScript来检测用户在页面上滚动的距离,如果他们滚动超过某个点(比如文章的80%),您可以触发一个AJAX请求,该请求会记录用户滚动过去的那个点。

Quick example in jQuery: 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. 没有测试,并且你想要将1000改为像素数量,直到你到达文章中的元素,因此它适用于不同的文章长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Lynx中查看我的网页时隐藏div? - How can I hide a div when my webpage is viewed in Lynx? 如何确定何时查看HTML5元素? - How to determine when an HTML5 element has been viewed? Rails和Javascript-如何将某些内容标记为已查看或已读取? - Rails & Javascript - How to mark something as viewed or read? React Developer Tools如何确定网页正在使用React? - How does React Developer Tools determine that the webpage is using React? 当Javascript变量为“正确”时,如何使某些内容出现在HTML网页上? - How to make something appear on an HTML webpage when Javascript variables are 'correct'? 在从本地计算机的浏览器中查看网页时,与从服务器的浏览器中查看网页时所显示的页面不同 - Webpage displays differently when viewed in a browser from the local machine than when viewed in a browser from the server 如何确定用户何时离开网页(某些链接除外) - How to determine when a user is leaving a webpage (excluding certain links) 在 Web 开发人员工具中查看时插入网页的奇怪代码 - Strange code inserted into webpage when viewed in Web Developer Tools ReactJS:如何确定应用程序是在移动浏览器还是桌面浏览器上查看 - ReactJS: How to determine if the application is being viewed on mobile or desktop browser 如何使用 python 从网页获取内容 - How to get something from a webpage with python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM