1. JS 禁止右鍵
<script type="text/javascript"> document.oncontextmenu=function(e){return false;} </script> <body onselectstart="return false"> ......
2. CSS 禁止複製和選取 如果讓整個頁面都禁止選擇
<style type="text/css"> body { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } </style>
如果是局部
<style type="text/css"> .unselectable { -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none; /* Introduced in IE 10. See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/ */ -ms-user-select: none; user-select: none; } </style>
3. 完整執行個體:
<style type="text/css"> body { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } </style> <script langauge="javascript"> document.oncontextmenu=function(e){return false;} </script> </head> <body onselectstart="return false"> ... ...
或者:
body{ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } function iEsc(){ return false; } function iRec(){ return true; } function DisableKeys() { if(event.ctrlKey || event.shiftKey || event.altKey) { window.event.returnValue=false; iEsc();} } document.ondragstart=iEsc; document.onkeydown=DisableKeys; document.oncontextmenu=iEsc; if (typeof document.onselectstart !="undefined") document.onselectstart=iEsc; else { document.onmousedown=iEsc; document.onmouseup=iRec; } function DisableRightClick(e) { if (window.Event){ if (e.which == 2 || e.which == 3) iEsc();} else if (event.button == 2 || event.button == 3) { event.cancelBubble = true event.returnValue = false; iEsc(); } }
其他常用的JS代碼(js禁止的一些功能) 禁止查看源檔案
<script>function clear(){Source=document.body.firstChild.data;document.open();document.close();document.title=”看不到原始碼”;document.body.innerHTML=Source;}</script>
圖片下載限制
<script language=”javascript”>function Click(){if(window.event.srcElement.tagName==”IMG”){alert(‘圖片直接右鍵’);window.event.returnValue=false;}}document.oncontextmenu=Click;</script>
<pre name="code" class="html"><META HTTP-EQUIV=”imagetoolbar” CONTENT=”no”>
插入圖片時加入galleryimg屬性
<img galleryimg=”no” src=””>
禁止右鍵儲存
把下面代碼放在<head>和</head>之間
<SCRIPT LANGUAGE=java script>function click() {alert(‘對不起,您不能儲存此圖片,謝謝您的理解和支援!’) }function click1() {if (event.button==2) {alert(‘對不起,您不能儲存此圖片,謝謝您的理解和支援!’) }}function CtrlKeyDown(){if (event.ctrlKey) {alert(‘不當的拷貝將損害您的系統。’) }}document.onkeydown=CtrlKeyDown;document.onselectstart=click;document.onmousedown=click1;</SCRIPT>
方式二:
在頁面中加入如下js代碼:原理:屏蔽右鍵
<script>function document.onmousedown(){ if(event.button==2||event.button==3) { alert( “右健被禁止 “) return false }}</script>
頁面禁止重新整理完全
最好在pop出來的視窗裡用,沒工具列的
<body onkeydown=”KeyDown()” onbeforeunload=”location=location”oncontextmenu=”event.returnValue=false”><script language=”Javascript”><!–function KeyDown(){if ((window.event.altKey)&&((window.event.keyCode==37)||(window.event.keyCode==39))){ alert(“請訪問我的首頁”);event.returnValue=false;}if ((event.keyCode==8)|| (event.keyCode==116)){ //屏蔽 F5 重新整理鍵event.keyCode=0;event.returnValue=false;}if ((event.ctrlKey)&&(event.keyCode==78)){ //屏蔽 Ctrl+nevent.returnValue=false;}if ((event.shiftKey)&&(event.keyCode==121)){ //屏蔽 shift+F10event.returnValue=false;}}</script></body
轉自:http://www.chhua.com/web-note2825
http://justcoding.iteye.com/blog/1999249