js實(shí)現(xiàn)簡單鎖屏功能實(shí)例
本文實(shí)例講述了js實(shí)現(xiàn)簡單鎖屏功能的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
//********* 鎖屏DIV ***************************
function LockScreen(tag,title,width,height,url)
{
if (tag) //鎖屏
{
var lockdiv = document.getElementById("lockscreen");
if (lockdiv!=null)
{
lockdiv.style.display = "block";
var subdiv = document.getElementById("subdialog");
if (subdiv!=null)
{
subdiv.style.display = "block";
document.getElementById("dialog1").src = url;
}
}else{
//創(chuàng)建新的鎖屏DIV,并執(zhí)行鎖屏
var tabframe= document.createElement("div");
tabframe.id = "lockscreen";
tabframe.name = "lockscreen";
tabframe.style.top = '0px';
tabframe.style.left = '0px';
tabframe.style.height = '100%';
tabframe.style.width = '100%';
tabframe.style.position = "absolute";
tabframe.style.filter = "Alpha(opacity=10)";
tabframe.style.backgroundColor="#000000";
tabframe.style.zIndex = "99998";
document.body.appendChild(tabframe);
tabframe.style.display = "block";
//子DIV
var subdiv = document.createElement("div");
subdiv.id = "subdialog";
subdiv.name = "subdialog";
subdiv.style.top = Math.round((tabframe.clientHeight-height)/2);
subdiv.style.left = Math.round((tabframe.clientWidth-width)/2);
subdiv.style.height = height+'px';
subdiv.style.width = width+'px';
subdiv.style.position = "absolute";
subdiv.style.backgroundColor="#000000";
subdiv.style.zIndex = "99999";
subdiv.style.filter = "Alpha(opacity=100)";
subdiv.style.border = "1px";
//subdiv.onmousemove = mouseMoveDialog;
//subdiv.onmousedown = control_onmousedown;
//subdiv.onmouseup = mouseUp;
document.body.appendChild(subdiv);
subdiv.style.display = "block";
//subdiv.onclick=UNLockScreen;
var iframe_height = height-30;
var titlewidth = width;
var html = "<table border='0' cellpadding='0' cellspacing='0'>"
html += "<tr><td></td><td>";
html += "<table><tr><td><font color='#FFFFFF'><b>"+title+"</b></font></td><td style='width:30px' valign='top'><img src='/images/images/close.gif' ></img></td></tr></table>";
html += "</td><td></td></tr>";
html += "<tr><td></td><td style='height:100px;'><iframe id='dialog1' frameborder=0 style='width:"+titlewidth+"px;height:" + iframe_height + "px' src='"+url+"'></iframe></td><td></td></tr>";
html += "<td></td><td></td><td></td>";
html += "</table>";
subdiv.innerHTML = html;
}
}else{
//解屏
var lockdiv = document.getElementById("lockscreen");
if (lockdiv!=null)
{
lockdiv.style.display = "none";
}
var subdiv = document.getElementById("subdialog");
if (subdiv!=null)
{
subdiv.style.display = "none";
}
}
}
function UNLockScreen(){
LockScreen(false);
}
如果大家不知道什么是鎖屏,可以去163信箱看一看,用途是你要離開屏幕一段時(shí)間時(shí)可以暫時(shí)鎖住屏幕保留工作空間。帶回來只要重新輸入密碼驗(yàn)證即可恢復(fù)到原先的工作空間。
一般都是通過在頁面上增加不透明遮罩層實(shí)現(xiàn)鎖屏功能,或者是使用兩個(gè)區(qū)域互相顯示隱藏。使用框架(frame)構(gòu)建的網(wǎng)站如果要實(shí)現(xiàn)鎖屏功能則很有難度。因?yàn)樵诳蚣茼撁鏌o法使用div做層。而且框架也不支持css的display:none;屬性。
最后的實(shí)現(xiàn)方法是使用在FRAMESET內(nèi)再增加一個(gè)frame,出事狀態(tài)時(shí)FRAMESET的rows屬性將新增加的frame設(shè)置為高度為0。點(diǎn)擊鎖屏按鈕時(shí),則將FRAMESET中其他的frame的高度設(shè)置為0,將新增的frame高度設(shè)置為*。這樣我們就完成了frame的替換功能。解鎖后將 FRAMESET的rows屬性重新設(shè)置為初始值,屏幕恢復(fù)到原狀態(tài)。
這樣并沒有結(jié)束。如果用戶在屏幕上使用右鍵刷新,或者按F5鍵刷新頁面,就會繞過鎖屏的密碼校驗(yàn)功能??梢酝ㄟ^阻止F5和鼠標(biāo)右鍵的默認(rèn)實(shí)現(xiàn)達(dá)到目的。
//阻止F5或者鼠標(biāo)右鍵刷新,使鎖屏失效。
document.onkeydown = function(){
if(event.keyCode==116) {
event.keyCode=0;
event.returnValue = false;
}
}
document.oncontextmenu = function() {event.returnValue = false;}
最后調(diào)用的方法:
希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
js對象屬性名駝峰式轉(zhuǎn)下劃線的實(shí)例代碼
這篇文章主要介紹了js對象屬性名駝峰式轉(zhuǎn)下劃線的實(shí)例代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
javascript中利用數(shù)組實(shí)現(xiàn)的循環(huán)隊(duì)列代碼
javascript中利用數(shù)組實(shí)現(xiàn)的循環(huán)隊(duì)列代碼,需要的朋友可以參考下。2010-01-01
javascript replace()正則替換實(shí)現(xiàn)代碼
javascript-replace()基礎(chǔ),一次完成將"<,>"替換"<>"實(shí)例2010-02-02
JS/jQuery實(shí)現(xiàn)DIV延時(shí)幾秒后消失或顯示的方法
這篇文章主要介紹了JS/jQuery實(shí)現(xiàn)DIV延時(shí)幾秒后消失或顯示的方法,結(jié)合實(shí)例形式分析了javascript使用setTimeout及jQuery使用delay方法實(shí)現(xiàn)延遲顯示功能的相關(guān)操作技巧,需要的朋友可以參考下2018-02-02
JavaScript實(shí)現(xiàn)網(wǎng)頁跨年倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)網(wǎng)頁跨年倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12

