如何设置网页定时自动刷新,实现长时间在线浏览?

2026-04-06 12:201阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计178个文字,预计阅读时间需要1分钟。

如何设置网页定时自动刷新,实现长时间在线浏览?

监听网页键盘和鼠标事件,长时间无操作自动刷新页面:定时刷新页面,默认30分钟无操作则刷新

如何设置网页定时自动刷新,实现长时间在线浏览?

监听网页的键盘和鼠标事件,长时间无操作则刷新页面

/** * 页面刷新 * @param time 单位为分钟 */ function timeRefresh(time) { var xIndex ; var yIndex ; var count = 0; var outTime=30; //默认30分钟无操作则刷新 if (time != undefined && time != "" && time != null) { outTime=time; } //监听鼠标 document.onmousemove = function (event) { var xMouse = event.clientX; var yMouse = event.clientY; if (xIndex != xMouse || yIndex != yMouse) { count = 0; //鼠标移动,计数清0 } xIndex = xMouse; //记录本次鼠标移动位置 yIndex = yMouse; }; //监听键盘 document.onkeydown = function () { count = 0; //键盘按下,计数清0 }; window.setInterval(timeCount, 1000); function timeCount() { count++; if (count == outTime*60) { window.location.reload(); } } }

本文共计178个文字,预计阅读时间需要1分钟。

如何设置网页定时自动刷新,实现长时间在线浏览?

监听网页键盘和鼠标事件,长时间无操作自动刷新页面:定时刷新页面,默认30分钟无操作则刷新

如何设置网页定时自动刷新,实现长时间在线浏览?

监听网页的键盘和鼠标事件,长时间无操作则刷新页面

/** * 页面刷新 * @param time 单位为分钟 */ function timeRefresh(time) { var xIndex ; var yIndex ; var count = 0; var outTime=30; //默认30分钟无操作则刷新 if (time != undefined && time != "" && time != null) { outTime=time; } //监听鼠标 document.onmousemove = function (event) { var xMouse = event.clientX; var yMouse = event.clientY; if (xIndex != xMouse || yIndex != yMouse) { count = 0; //鼠标移动,计数清0 } xIndex = xMouse; //记录本次鼠标移动位置 yIndex = yMouse; }; //监听键盘 document.onkeydown = function () { count = 0; //键盘按下,计数清0 }; window.setInterval(timeCount, 1000); function timeCount() { count++; if (count == outTime*60) { window.location.reload(); } } }