萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> js禁止頁面刷新與後退的方法

js禁止頁面刷新與後退的方法

   本文實例講述了js禁止頁面刷新與後退的方法。分享給大家供大家參考。具體實現方法如下:

  ?

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 43 44 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 78 79 80 81 82 <script language="javascript"> //禁止用F5鍵 function document.onkeydown() { if ( event.keyCode==116) { event.keyCode = 0; event.cancelBubble = true; return false; } } //禁止右鍵彈出菜單 function document.oncontextmenu() { return false; } //下面代碼實現全屏顯示 function window.onload(){ var Request = new Array();//保存參數 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"><!-- //屏蔽鼠標右鍵、Ctrl+N、Shift+F10、F11、F5刷新、退格鍵 //Author: meizz(梅花雨) 2002-6-18 function document.oncontextmenu(){event.returnValue=false;} //屏蔽鼠標右鍵 function window.onhelp(){return false} //屏蔽F1幫助 function document.onkeydown() { if ((window.event.altKey)&& ((window.event.keyCode==37)|| //屏蔽 Alt+ 方向鍵 ← (window.event.keyCode==39))) //屏蔽 Alt+ 方向鍵 → { alert("不准你使用ALT+方向鍵前進或後退網頁!"); event.returnValue=false; } /* 注:這還不是真正地屏蔽 Alt+ 方向鍵, 因為 Alt+ 方向鍵彈出警告框時,按住 Alt 鍵不放, 用鼠標點掉警告框,這種屏蔽方法就失效了。以後若 有哪位高手有真正屏蔽 Alt 鍵的方法,請告知。*/ if ((event.keyCode==8) || //屏蔽退格刪除鍵 (event.keyCode==116)|| //屏蔽 F5 刷新鍵 (event.ctrlKey && event.keyCode==82)){ //Ctrl + R event.keyCode=0; event.returnValue=false; } if (event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11 if (event.ctrlKey && event.keyCode==78) event.returnValue=false; //屏蔽 Ctrl+n if (event.shiftKey && event.keyCode==121)event.returnValue=false; //屏蔽 shift+F10 if (window.event.srcElement.tagName == "A" && window.event.shiftKey) window.event.returnValue = false; //屏蔽 shift 加鼠標左鍵新開一網頁 if ((window.event.altKey)&&(window.event.keyCode==115)) //屏蔽Alt+F4 { window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); return false; } } </script>

  希望本文所述對大家的javascript程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved