javascript实现锁定网页、密码解锁效果(类似系统屏幕保护效果)
作者:junjie 时间:2023-08-18 20:01:36
功能描述:打开一个网站的网页,过5分钟不动作,就会锁定页面,隐藏内容容器,显示一个容器用于输入密码,输入正确的密码来解锁。锁定后即使用户刷新页面,还是保留原来的状态。如已经锁定的,需要继续锁定,否则显示内容。
示例代码如下,通过document.onmouseover来实现多少分钟没有动作,使用计时器来实现。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript实现系统屏幕保护效果(锁定网页)</title>
</head>
<body>
<div id="dvContent">内容<br />内容<br />内容<br />内容<br />内容<br />内容</div>
<div id="dvPassword" style="display:none">输入密码:<input type="password" id="txtPwd" /><input type="button" value="确定" onclick="check()"/></div>
<script>
if (document.cookie.indexOf('lock=1') != -1) ShowContent(false);
var delay = 10 * 1000,timer;//10s后锁定,修改delay为你需要的时间,单位毫秒
function startTimer() {
clearTimeout(timer);
timer = setTimeout(TimerHandler, delay);
}
function TimerHandler() {
document.cookie = 'lock=1';
document.onmousemove = null;//锁定后移除鼠标移动事件
ShowContent(false);
}
function ShowContent(show) {
document.getElementById('dvContent').style.display = show ? 'block' : 'none';
document.getElementById('dvPassword').style.display = show ? 'none' : 'block';
}
function check() {
if (document.getElementById('txtPwd').value == '123') {
document.cookie = 'lock=0';
ShowContent(true);
startTimer()//重新计时
document.onmousemove = startTimer; //重新绑定鼠标移动事件
}
else alert('密码不正确!!');
}
window.onload = function () {
document.onmousemove = startTimer;
startTimer();
}
</script>
</body>
</html>
标签:javascript,锁定网页,密码解锁,屏幕保护效果
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Django之创建引擎索引报错及解决详解
2023-06-11 10:55:15
![](https://img.aspxhome.com/file/2023/5/59125_0s.png)
WEB开发中合理选择图片格式
2011-09-22 20:32:06
Python集成学习之Blending算法详解
2022-09-28 04:31:35
![](https://img.aspxhome.com/file/2023/1/130661_0s.jpg)
Python 带星号(* 或 **)的函数参数详解
2023-04-25 22:36:40
使用Numpy打乱数组或打乱矩阵行
2022-09-18 09:40:10
Pandas读取行列数据最全方法
2022-06-23 09:34:22
利用Python进行数据可视化常见的9种方法!超实用!
2021-10-05 23:11:58
![](https://img.aspxhome.com/file/2023/2/82632_0s.jpg)
Pycharm使用Database Navigator连接mysql数据库全过程
2024-01-15 03:58:35
![](https://img.aspxhome.com/file/2023/9/134619_0s.jpg)
Python的Flask框架中Flask-Admin库的简单入门指引
2021-11-06 03:30:19
![](https://img.aspxhome.com/file/2023/1/80561_0s.png)
详解Python的Django框架中的模版相关知识
2023-04-22 02:46:25
运用python去除图片水印
2021-05-06 10:54:20
![](https://img.aspxhome.com/file/2023/8/95278_0s.png)
python中xlwt模块的具体用法
2023-11-08 07:10:15
![](https://img.aspxhome.com/file/2023/4/92324_0s.png)
深入浅析Vue中mixin和extend的区别和使用场景
2024-05-29 22:42:43
python保存文件方法小结
2021-09-09 04:13:59
Python爬虫 scrapy框架爬取某招聘网存入mongodb解析
2023-06-23 09:35:59
![](https://img.aspxhome.com/file/2023/2/95192_0s.png)
PyQt5每天必学之工具提示功能
2023-03-12 09:22:00
![](https://img.aspxhome.com/file/2023/7/134507_0s.png)
FSO遍历文件夹目录及目录下文件asp代码
2008-10-10 12:54:00
关于MySql 10038错误的完美解决方法(三种)
2024-01-27 06:16:18
php session_start()出错原因分析及解决方法
2024-06-07 15:44:29
在Python中合并字典模块ChainMap的隐藏坑【推荐】
2022-11-16 09:48:18
![](https://img.aspxhome.com/file/2023/0/127920_0s.png)