国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

javascript實(shí)現(xiàn)鎖定網(wǎng)頁(yè)、密碼解鎖效果(類(lèi)似系統(tǒng)屏幕保護(hù)效果)

2024-04-25 20:31:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

打開(kāi)一個(gè)網(wǎng)站的網(wǎng)頁(yè),過(guò)5分鐘不動(dòng)作,就會(huì)鎖定頁(yè)面,隱藏內(nèi)容容器,顯示一個(gè)容器用于輸入密碼,輸入正確的密碼來(lái)解鎖。鎖定后即使用戶刷新頁(yè)面,還是保留原來(lái)的狀態(tài)。如已經(jīng)鎖定的,需要繼續(xù)鎖定,否則顯示內(nèi)容。javascript實(shí)現(xiàn)鎖定網(wǎng)頁(yè)、密碼解鎖效果,跟Windows系統(tǒng)的屏幕保護(hù)效果類(lèi)似,怎么實(shí)現(xiàn)呢?

示例代碼如下,通過(guò)document.onmouseover來(lái)實(shí)現(xiàn)多少分鐘沒(méi)有動(dòng)作,使用計(jì)時(shí)器來(lái)實(shí)現(xiàn)。
<!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實(shí)現(xiàn)系統(tǒng)屏幕保護(hù)效果(鎖定網(wǎng)頁(yè))</title>
</head>

 

<body>
<div id="dvContent">內(nèi)容<br />內(nèi)容<br />內(nèi)容<br />內(nèi)容<br />內(nèi)容<br />內(nèi)容</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為你需要的時(shí)間,單位毫秒
function startTimer() {
clearTimeout(timer);
timer = setTimeout(TimerHandler, delay);
}
function TimerHandler() {
document.cookie = 'lock=1';
document.onmousemove = null;//鎖定后移除鼠標(biāo)移動(dòng)事件
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()//重新計(jì)時(shí)
document.onmousemove = startTimer; //重新綁定鼠標(biāo)移動(dòng)事件
}
else alert('密碼不正確!!');
}
window.onload = function () {
document.onmousemove = startTimer;
startTimer();
}
</script>
</body>
</html>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青川县| 榆社县| 江孜县| 巴中市| 长海县| 河间市| 墨玉县| 云和县| 德庆县| 菏泽市| 都匀市| 湖口县| 兖州市| 敦化市| 武宁县| 连南| 安平县| 黔南| 海丰县| 轮台县| 永安市| 白山市| 黔西| 泰来县| 贞丰县| 松江区| 铅山县| 遂宁市| 繁峙县| 曲周县| 阿城市| 乐都县| 南岸区| 建瓯市| 蒙自县| 尚志市| 霍林郭勒市| 大关县| 舟曲县| 石河子市| 富蕴县|