javascript实现锁定网页、密码解锁效果(类似系统屏幕保护效果)
作者:bea
功能描述:打开一个网站的网页,过5分钟不动作,就会锁定页面,隐藏内容容器,显示一个容器用于输入密码,输入正确的密码来解锁。锁定后即使用户刷新页面,还是保留原来的状态。如已经锁定的,需要继续锁定,否则显示内容。 示例代码如下,通过document.onmouseover来实现多少分钟没有动作,使用计时器来实现。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.
功能描述:打开一个网站的网页,过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>
有用 | 无用
<!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>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jquery中$(#form :input)与$(#form input)的区别
- JQuery EasyUI 加载两次url的原因分析及解决方案
- javascript ajax的5种状态介绍
- jquery操作HTML5 的data-*的用法实例分享
- js判断浏览器是否支持html5
- 一段非常简单的js判断浏览器的内核
- JavaScript继承基础讲解(原型链、借用构造函数、混合模式、原型式继承、寄生式继承、寄生组合式继承)
- JS面向对象基础讲解(工厂模式、构造函数模式、原型模式、混合模式、动态原型模式)
- Node.js安装教程和NPM包管理器使用详解
- Node.js中的事件驱动编程详解
- Node.js文件操作详解
- Node.js中使用Buffer编码、解码二进制数据详解
- Node.js中创建和管理外部进程详解
- Node.js模块加载详解
- JS遍历Json字符串中键值对先转成JSON对象再遍历
- 手机端网页点击链接触发自动拨打或保存电话的示例代码
- Node.js中使用事件发射器模式实现事件绑定详解
- Node.js中使用计时器定时执行函数详解
- javascript中实现兼容JAVA的hashCode算法代码分享