1.屏蔽功能類?
1.1 屏蔽鍵盤所有鍵?
<script language="javascript">?
<!--?
function document.onkeydown(){?
event.keyCode = 0;?
event.returnvalue = false;?
}?
-->?
</script>?
1.2 屏蔽鼠標右鍵?
在body標簽里加上oncontextmenu=self.event.returnvalue=false?
或者?
<script language="javascript">?
<!--?
function document.oncontextmenu()?
{?
return false;?
}?
-->?
</script>?
function nocontextmenu()?
{?
if(document.all) {?
event.cancelBubble=true;?
event.returnvalue=false;?
return false;?
}?
}?
或者?
<body onmousedown="rclick()" oncontextmenu= "nocontextmenu()">?
<script language="javascript">?
<!--?
function rclick()?
{?
if(document.all) {?
if (event.button == 2){?
event.returnvalue=false;?
}?
}?
}?
-->?
</script>?
1.3 屏蔽 Ctrl+N、Shift+F10、F5刷新、退格鍵?
<script language="javascript">?
<!--?
//屏蔽鼠標右鍵、Ctrl+N、Shift+F10、F5刷新、退格鍵?
function window.onhelp(){return false} //屏蔽F1幫助?
function KeyDown(){?
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 ==

(event.srcElement.type != "text" &&?
event.srcElement.type != "textarea" &&?
event.srcElement.type != "password") || //屏蔽退格刪除鍵?
(event.keyCode ==116)|| //屏蔽 F5 刷新鍵?
(event.ctrlKey && event.keyCode==82)){ //Ctrl + R?
event.keyCode=0;?
event.returnvalue=false;?
}?
if ((event.ctrlKey)&&(event.keyCode==78)) //屏蔽 Ctrl+n?
event.returnvalue=false;?
if ((event.shiftKey)&&(event.keyCode==121)) //屏蔽 shift+F10?
event.returnvalue=false;?
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;}?
}?
/* 另外可以用 window.open 的方法屏蔽 IE 的所有菜單?
第一種方法:?
window.open("你的.htm", "","toolbar=no,location=no,directories= no,menubar=no,scrollbars=no,resizable=yes,status=no,top=0,left=0")?
第二種方法是打開一個全屏的頁面:?
window.open("你的.asp", "", "fullscreen=yes")?
*/?
//-->?
</script>?
1.4屏蔽瀏覽器右上角“最小化”“最大化”“關閉”鍵?
<script language=javascript>?
function window.onbeforeunload()?
{?
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)?
{?
window.event.returnvalue = "";?
}?
}?
</script>?
或者使用全屏打開頁面?
<script language="javascript">?
<!--?
window.open(www.32pic.com,"32pic","fullscreen=3,height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");?
-->?
</script>?
注:在body標簽里加上onbeforeunload="javascript:return false"(使不能關閉窗口)?
1.5屏蔽F5鍵?
<script language="javascript">?
<!--?
function document.onkeydown()?
{?
if ( event.keyCode==116)?
{?
event.keyCode = 0;?
event.cancelBubble = true;?
return false;?
}?
}?
-->?
</script>?
1.6屏蔽IE后退按鈕?
在你鏈接的時候用 <a href="javascript:location.replace(url)">?
1.7屏蔽主窗口滾動條?
在body標簽里加上 style="overflow-y:hidden"?
1.8 屏蔽拷屏,不斷地清空剪貼板?
在body標簽里加上onload="setInterval('clipboardData.setData(\'Text\',\'\')',100)"?
1.9 屏蔽網站的打印功能?
<style>?
@media print {?
* { display: none }?
}?
</style>?
1.10 屏蔽IE6.0 圖片上自動出現的保存圖標?
方法一:?
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">?
方法二:?
<img galleryimg="no">?
1.11 屏蔽頁中所有的script?
<noscrript></noscript>?
2.表單提交驗證類?
2.1 表單項不能為空?
<script language="javascript">?
<!--?
function CheckForm()?
{?
if (document.form.name.value.length == 0) {?
alert("請輸入您姓名!");?
document.form.name.focus();?
return false;?
}?
return true;?
}?
-->?
</script>?
2.2 比較兩個表單項的值是否相同?
<script language="javascript">?
<!--?
function CheckForm()?
if (document.form.PWD.value != document.form.PWD_Again.value) {?
alert("您兩次輸入的密碼不一樣!請重新輸入.");?
document.ADDUser.PWD.focus();?
return false;?
}?
return true;?
}?
-->?
</script>?
2.3 表單項只能為數字和"_",用于電話/銀行帳號驗證上,可擴展到域名注冊等?
<script language="javascript">?
<!--?
function isNumber(String)?
{?
var Letters = "1234567890-"; //可以自己增加可輸入值?
var i;?
var c;?
if(String.charAt( 0 )=='-')?
return false;?
if( String.charAt( String.length - 1 ) == '-' )?
return false;?
for( i = 0; i < String.length; i ++ )?
{?
c = String.charAt( i );?
if (Letters.indexOf( c ) < 0)?
return false;?
}?
return true;?
}?
function CheckForm()?
{?
if(! isNumber(document.form.TEL.value)) {?
alert("您的電話號碼不合法!");?
document.form.TEL.focus();?
return false;?
}?
return true;?
}?
-->?
</script>?
2.4 表單項輸入數值/長度限定?
<script language="javascript">?
<!--?
function CheckForm()?
{?
if (document.form.count.value > 100 || document.form.count.value < 1)?
{?
alert("輸入數值不能小于零大于100!");?
document.form.count.focus();?
return false;?
}?
if (document.form.MESSAGE.value.length<10)?
{?
alert("輸入文字小于10!");?
document.form.MESSAGE.focus();?
return false;?
}?
return true;?
}?
//-->?
</script>?
2.5 中文/英文/數字/郵件地址合法性判斷?
<SCRIPT LANGUAGE="javascript">?
<!--?
function isEnglish(name) //英文值檢測?
{?
if(name.length == 0)?
return false;?
for(i = 0; i < name.length; i++) {?
if(name.charCodeAt(i) > 128)?
return false;?
}?
return true;?
}?
function isChinese(name) //中文值檢測?
{?
if(name.length == 0)?
return false;?
for(i = 0; i < name.length; i++) {?
if(name.charCodeAt(i) > 128)?
return true;?
}?
return false;?
}?
function isMail(name) // E-mail值檢測?
{?
if(! isEnglish(name))?
return false;?
i = name.indexOf("@");?
j = name.lastIndexOf("@");?
if(i == -1)?
return false;?
if(i != j)?
return false;?
if(i == name.length)?
return false;?
return true;?
}?
function isNumber(name) //數值檢測?
{?
if(name.length == 0)?
return false;?
for(i = 0; i < name.length; i++) {?
if(name.charAt(i) < "0" || name.charAt(i) > "9")?
return false;?
}?
return true;?
}?
function CheckForm()?
{?
if(! isMail(form.Email.value)) {?
alert("您的電子郵件不合法!");?
form.Email.focus();?
return false;?
}?
if(! isEnglish(form.name.value)) {?
alert("英文名不合法!");?
form.name.focus();?
return false;?
}?
if(! isChinese(form.cnname.value)) {?
alert("中文名不合法!");?
form.cnname.focus();?
return false;?
}?
if(! isNumber(form.PublicZipCode.value)) {?
alert("郵政編碼不合法!");?
form.PublicZipCode.focus();?
return false;?
}?
return true;?
}?
//-->?
</SCRIPT>?
2.6 限定表單項不能輸入的字符?
<script language="javascript">?
<!--?
function contain(str,charset)// 字符串包含測試函數?
{?
var i;?
for(i=0;i<charset.length;i++)?
if(str.indexOf(charset.charAt(i))>=0)?
return true;?
return false;?
}?
function CheckForm()?
{?
if ((contain(document.form.NAME.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><")))?
{?
alert("輸入了非法字符");?
document.form.NAME.focus();?
return false;?
}?
return true;?
}?
//-->?
</script>??
2 function Click(){
3 if (event.button!=1){alert('版權所有(C)2001 XXX工作室');
4 }}
5 document.onmousedown=Click;
1 <Script type=”text/javascript”>
2 function Click(){
3 if (event.button!=1){alert('版權所有(C)2001 XXX工作室');
4 }}
5 document.onmousedown=Click;
這樣在瀏覽網頁時除單擊鼠標左鍵外,其他任何形式的鼠標點擊或組合點擊,都將出現“版權所有(C)2001 XXX工作室”的提示框,而不是出現快捷菜單,從而避免被人查看源文件代碼。 如果使event.button=2,實際上它僅能限制點擊鼠標右鍵情況,其他點擊方式,如按左右鍵、按左和中間鍵、按中間鍵等就不能限制,當這些方式的點擊發生時,出現的就是快捷菜單,從而可以查看源文件。 注意:把body改為如下代碼:,其中Value中的V一定要大寫!! 頁面禁用鼠標右鍵代碼 可以把下面代碼加入到頁面適當位置。 LeadBBS論壇應用下面代碼時,可以打開:inc/Board_Popfun.asp文件 查找: 下面加入代碼。 1 <script language=javascript>
2 function openScript(url, width, height,left,top,r){
3 var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',left=' +left+ ',top='+top+',resizable=no,scrollbars='+r+',menubar=no,status=no' );
4 }
1 <script language=javascript>
2 function openScript(url, width, height,left,top,r){
3 var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',left=' +left+ ',top='+top+',resizable=no,scrollbars='+r+',menubar=no,status=no' );
4 }
//以下為禁止鼠標右鍵的代碼,不想禁止的可以刪除 01 <!--
02
03 if (window.Event)
04 document.captureEvents(Event.MOUSEUP);
05
06 function nocontextmenu()
07 {
08 event.cancelBubble = true
09 event.returnValue = false;
10
11 return false;
12 }
13
14 function norightclick(e)
15 {
16 if (window.Event)
17 {
18 if (e.which == 2 || e.which == 3)
19 return false;
20 }
21 else
22 {if (event.button == 2 || event.button == 3) {alert("【E路極速】歡迎你"); } }
23 {
24 event.cancelBubble = true
25 event.returnValue = false;
26 return false;
27 }
28
29 }
30
31 document.oncontextmenu = nocontextmenu; // for IE5+
32 document.onmousedown = norightclick; // for all others
33 //-->
34 </script>
01 <!--
02
03 if (window.Event)
04 document.captureEvents(Event.MOUSEUP);
05
06 function nocontextmenu()
07 {
08 event.cancelBubble = true
09 event.returnValue = false;
10
11 return false;
12 }
13
14 function norightclick(e)
15 {
16 if (window.Event)
17 {
18 if (e.which == 2 || e.which == 3)
19 return false;
20 }
21 else
22 {if (event.button == 2 || event.button == 3) {alert("【E路極速】歡迎你"); } }
23 {
24 event.cancelBubble = true
25 event.returnValue = false;
26 return false;
27 }
28
29 }
30
31 document.oncontextmenu = nocontextmenu; // for IE5+
32 document.onmousedown = norightclick; // for all others
33 //-->
34 </script>
圖片禁用鼠標右鍵代碼 應用方法同上。 01 <script language="JavaScript1.2">
02 var clickmessage="本站圖片禁用右鍵!"
03 function disableclick(e) {
04 if (document.all) {
05 if (event.button==2||event.button==3) {
06 if (event.srcElement.tagName=="IMG"){
07 alert(clickmessage);
08 return false;
09 }
10 }
11 }
12 if (document.layers) {
13 if (e.which == 3) {
14 alert(clickmessage);
15 return false;
16 }
17 }
18 }
19
20 function associateimages(){
21 for(i=0;i<document.images.length;i++)
22 document.images[i].onmousedown=disableclick;
23 }
24
25 if (document.all)
26 document.onmousedown=disableclick
27 else if (document.layers)
28 associateimages()
29 </script>
01 <script language="JavaScript1.2">
02 var clickmessage="本站圖片禁用右鍵!"
03 function disableclick(e) {
04 if (document.all) {
05 if (event.button==2||event.button==3) {
06 if (event.srcElement.tagName=="IMG"){
07 alert(clickmessage);
08 return false;
09 }
10 }
11 }
12 if (document.layers) {
13 if (e.which == 3) {
14 alert(clickmessage);
15 return false;
16 }
17 }
18 }
19
20 function associateimages(){
21 for(i=0;i<document.images.length;i++)
22 document.images[i].onmousedown=disableclick;
23 }
24
25 if (document.all)
26 document.onmousedown=disableclick
27 else if (document.layers)
28 associateimages()
29 </script>
功能:禁止右鍵、禁選擇、禁粘貼、禁shift、禁ctrl、禁alt 01 <script language="JavaScript">
02 <!--
03 function key(){
04 if(event.shiftKey){
05 window.close();}
06 //禁止Shift
07 if(event.altKey){
08 window.close();}
09 //禁止Alt
10 if(event.ctrlKey){
11 window.close();}
12 //禁止Ctrl
13 return false;}
14 document.onkeydown=key;
15 if (window.Event)
16 document.captureEvents(Event.MOUSEUP);
17 function nocontextmenu(){
18 event.cancelBubble = true
19 event.returnValue = false;
20 return false;}
21 function norightclick(e){
22 if (window.Event){
23 if (e.which == 2 || e.which == 3)
24 return false;}
25 else
26 if (event.button == 2 || event.button == 3){
27 event.cancelBubble = true
28 event.returnValue = false;
29 return false;}
30 }
31 //禁右鍵
32 document.oncontextmenu = nocontextmenu; // for IE5+
33 document.onmousedown = norightclick; // for all others
34 //-->
35 </script>
01 <script language="JavaScript">
02 <!--
03 function key(){
04 if(event.shiftKey){
05 window.close();}
06 //禁止Shift
07 if(event.altKey){
08 window.close();}
09 //禁止Alt
10 if(event.ctrlKey){
11 window.close();}
12 //禁止Ctrl
13 return false;}
14 document.onkeydown=key;
15 if (window.Event)
16 document.captureEvents(Event.MOUSEUP);
17 function nocontextmenu(){
18 event.cancelBubble = true
19 event.returnValue = false;
20 return false;}
21 function norightclick(e){
22 if (window.Event){
23 if (e.which == 2 || e.which == 3)
24 return false;}
25 else
26 if (event.button == 2 || event.button == 3){
27 event.cancelBubble = true
28 event.returnValue = false;
29 return false;}
30 }
31 //禁右鍵
32 document.oncontextmenu = nocontextmenu; // for IE5+
33 document.onmousedown = norightclick; // for all others
34 //-->
35 </script>
如何用用javascript 禁止右鍵,禁止復制,禁止粘貼,做站時常會用到這些代碼,所以收藏了一下! 1. oncontextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標右鍵特效 no
可用于Table 2. 取消選取、防止復制 javascript技巧 3. onpaste="return false" 不準粘貼技巧 4. oncopy="return false;" oncut="return false;" 防止復制的javascirpt特效
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
