This paper illustrates the method of realizing simple lock-screen function of JS. Share to everyone for your reference. The implementation methods are as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
Lock-screen div *************************** function lockscreen (tag,title,width,height,url) {if (tag)//Lock screen {var lockd IV = 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{//Create new lock screen div and execute lock screen 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"; Sub 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 ' 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{//Jie Shi 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);} |
If you do not know what is a lock screen, you can go to the 163 box to look at, use is to leave the screen for a period of time you can temporarily lock the screen to keep the workspace. Bring it back. Once you re-enter the password verification, you can revert to your original workspace.
It is generally done by adding an opaque mask layer to the page to achieve the lock screen, or using two areas to show each other hidden. Web sites built using frames (frame) are difficult to implement when locking the screen. Because you can't use div to do layers on frames pages. Also, the framework does not support CSS Display:none properties.
The final implementation is to use a frame in the frameset, and the frameset rows property will set the newly added frame to a height of 0 when the state of the accident occurs. When you click the Lock Screen button, the height of the other frame in the frameset is set to 0, and the new frame height is set to *. This completes the replacement function of the frame. After unlocking, reset the frameset rows property to its original value, and the screen reverts to its native state.
This is not the end. If the user uses the right key to refresh on the screen, or presses the F5 key to refresh the page, it bypasses the lock screen's password check function. You can achieve the goal by blocking the default implementation of the F5 and the right mouse button.
?
| 1 2 3 4 5 6 7 8 |
Prevent the F5 or the right mouse button from refreshing to disable the lock screen. Document.onkeydown = function () {if (event.keycode==116) {event.keycode=0; event.returnvalue = false;}} Document.oncont Extmenu = function () {event.returnvalue = false;} |
Last method called:
Copy code code as follows:
Lockscreen (True, ' title ', 424,314, ' http://www.baidu.com ');
The
wants this article to help you with your JavaScript programming.