如何知道用户已经从浏览器开发工具到达页面末尾

How to know user have reached end of the page from Browser Dev tools

本文关键字:开发工具 浏览器 用户 何知道      更新时间:2023-09-26

浏览器开发工具是一个很棒的工具。我想知道用户是否已经从浏览器控制台到达页面的末尾。当我尝试使用javascript时,它说的是"未定义"

我们应该如何处理Ajax加载的页面?如何发现用户是否已经到达AJAX加载页面的末尾?

在控制台中尝试以下代码:(来源:请参阅链接)

setInterval(function(){
  var totalHeight;
  var currentScroll;
  var visibleHeight;
  if(document.documentElement.scrollTop){ 
      currentScroll = document.documentElement.scrollTop; 
  }else{ 
      currentScroll = document.body.scrollTop; 
  }
  totalHeight = document.body.offsetHeight;
  visibleHeight = document.documentElement.clientHeight;      
  if (totalHeight <= currentScroll + visibleHeight ){
    console.log('bottom of page');
  } 
 }, 1000);