JavaScript代碼實現(xiàn)禁止右鍵、禁選擇、禁粘貼、禁shift、禁ctrl、禁alt
廢話不多說了直接給大家貼代碼了。
代碼如下:
<script language="JavaScript"> <!-- //js禁用某些鍵的代碼 //www.dbjr.com.cn function key(){ if(event.shiftKey){ window.close();} //禁止Shift if(event.altKey){ window.close();} //禁止Alt if(event.ctrlKey){ window.close();} //禁止Ctrl return false;} document.onkeydown=key; if (window.Event) document.captureEvents(Event.MOUSEUP); function nocontextmenu(){ event.cancelBubble = true event.returnValue = false; return false;} function norightclick(e){ if (window.Event){ if (e.which == 2 || e.which == 3) return false;} else if (event.button == 2 || event.button == 3){ event.cancelBubble = true event.returnValue = false; return false;} } //禁右鍵 document.oncontextmenu = nocontextmenu; // for IE5+ document.onmou<a href="http://www.dbjr.com.cn/article/1141.html" target="_blank" class="infotextkey">sed</a>own = norightclick; // for all others //--> </script>
<body onselectstart="return false"; onpaste="return false";>
1. oncontextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標(biāo)右鍵特效
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消選取、防止復(fù)制
3. onpaste="return false" 不準(zhǔn)粘貼
4. oncopy="return false;" oncut="return false;" 防止復(fù)制
PS:JS防止后退,刷新,關(guān)閉的解決辦法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head> <title> New Document </title> </head> <script language="javascript"> function RunOnBeforeUnload() {window.onbeforeunload = function(){ return '將丟失未保存的數(shù)據(jù)!'; } } </script> <body onload="RunOnBeforeUnload()"> 刷新,關(guān)閉,后退,F5 測試 </body> </html>
雖然onbeforeunload這個事件已經(jīng)Web標(biāo)準(zhǔn)被淘汰,但目前能實現(xiàn)這個效果的也就只有這個事件.還好瀏覽器都能很好的支持.
測試結(jié)果:
IE6.0,FireFox,Chrome通過
相關(guān)文章
js 實現(xiàn)圖片預(yù)加載(js操作 Image對象屬性complete ,事件onload 異步加載圖片)
通過js操縱DOM很多情況下都是為了實現(xiàn)和當(dāng)前頁html元素的異步載入,我談?wù)剬mage對象的一些認(rèn)識。2011-03-03JS函數(shù)(普通函數(shù),箭頭函數(shù))中this的指向問題詳解
這篇文章主要給大家介紹了JS中普通函數(shù)和箭頭函數(shù)的this指向,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-09-09