Example 1
The code is as follows |
Copy Code |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <title> New Document </title> <script language= "JavaScript" > function Runonbeforeunload () {window.onbeforeunload = function () {return ' will lose unsaved data! '}} </script> <body onload= "Runonbeforeunload ()" > Refresh, close, rewind, F5 test </body>
|
Although the onbeforeunload event has been eliminated by the Web Standard, this is the only event that can be achieved. Fortunately, the browser can be very good support.
Test results:
Ie6.0,firefox,chrome through
It's just a hint to the user, and the following is a complete ban on these operations.
The code is as follows |
Copy Code |
<script language= "JavaScript" > Prohibit using F5 key function Document.onkeydown () { if (event.keycode==116) { Event.keycode = 0; Event.cancelbubble = true; return false; } }
Disable Right-click pop-up menu function Document.oncontextmenu () { return false; }
The following code implements full screen display function Window.onload () { var Request = new Array ()//Save Parameters var s = location.search.substring (1); if (s && s!= "") { var list = S.split ("&"); for (Var i=0; i < list.length; i++) { var pair = List[i].split ("="); if (Pair[0] && pair[0]!= "") { Request[unescape (pair[0])] = unescape (pair[1]); } } }
var fullscreen=request["fullscreen"]; if (fullscreen!= "yes") { var file =self.location; var a = window.open ("About:blank", "", "Fullscreen=yes") Self.opener=null Self.close () A.location=file + "Fullscreen=yes"; } } </script> <script language= "Javascript" ><!-- Screen the right mouse button, CTRL + N, SHIFT+F10, F11, F5 refresh, backspace key Author:meizz (Plum blossom rain) 2002-6-18 function Document.oncontextmenu () {event.returnvalue=false;} Mask right mouse button function Window.onhelp () {return false}//Shield F1 Help function Document.onkeydown () { if ((Window.event.altKey) && ((window.event.keycode==37) | |//Shielding ALT + Direction key ← (window.event.keycode==39))) Shielding Alt + Direction key → { Alert ("You are not allowed to use ALT + arrow keys forward or back page!") "); Event.returnvalue=false; } * Note: This is not really shielding ALT + arrow keys, Because ALT + ARROW keys pop-up warning box, hold down the ALT key, With the mouse point off the warning box, this shielding method is invalid. Later if There is a master who has really shielded the Alt key method, please inform. */ if ((event.keycode==8) | |//SHIELDING BACKSPACE Delete key (event.keycode==116) | | Mask F5 Refresh Key (Event.ctrlkey && event.keycode==82)) {//ctrl + R event.keycode=0; Event.returnvalue=false; } if (event.keycode==122) {event.keycode=0;event.returnvalue=false;}//Mask F11 if (Event.ctrlkey && event.keycode==78) Event.returnvalue=false; Block CTRL + N if (Event.shiftkey && event.keycode==121) Event.returnvalue=false; Shielding SHIFT+F10 if (Window.event.srcElement.tagName = "A" && Window.event.shiftKey) Window.event.returnValue = false; Screen shift plus left mouse button new page open if ((Window.event.altKey) && (window.event.keycode==115))//Shielding ALT+F4 { Window.showmodelessdialog ("About:blank", "" "," dialogwidth:1px;dialogheight:1px "); return false; } } </script> |