JavaScript屏蔽鍵盤常用代碼

來源:互聯網
上載者:User

在你連結的時候用

<a href="網頁特效:
location.replace(url)">
JavaScript屏蔽主視窗捲軸

在body標籤裡加上
style="overflow-y:hidden"
JavaScript屏蔽拷屏,不斷地清空剪貼簿
在body標籤裡加上
onload="setInterval('clipboardData.setData('Text','')',100)"
JavaScript屏蔽網站的列印功能
<style>
@media print {
   * { display: none }
}
</style>

JavaScript屏蔽IE6.0 圖片上自動出現的儲存表徵圖
方法一:

<META HTTP-EQUIV="imagetoolbar" CONTENT="no">

方法二:

<img galleryimg="no">
JavaScript屏蔽頁中所有的script
<noscrript></noscript>


JavaScript屏蔽F5鍵
代碼如下

<script language="javascript">
<!--
function document.onkeydown() 

    if ( event.keyCode==116) 
    { 
        event.keyCode = 0; 
        event.cancelBubble = true; 
        return false; 
    }
}
-->
</script>

屏蔽瀏覽器右上方“最小化”“最大化”“關閉”鍵

<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.zutiai.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"(使不能關閉視窗)


實現屏蔽鍵盤所有鍵的javascript代碼如下:

<script language="javascript">
<!--
function document.onkeydown(){
   event.keyCode = 0;
   event.returnvalue = false;
}
-->
</script>


屏蔽滑鼠右鍵、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 鍵不放,用滑鼠點掉警告框,這種屏蔽方法就失效了。

if ((event.keyCode == 8) &&
(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")

JavaScript屏蔽滑鼠右鍵還可以在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>
另外


oncontextmenu="window.event.returnvalue=false" 將徹底屏蔽滑鼠右鍵
<table border oncontextmenu=return(false)><td>no</table>
可用於Table

<body onselectstart="return false"> 取消選取、防止複製

oncopy="return false;" oncut="return false;" 防止複製


JavaScript屏蔽關鍵字,大概的思路就是去用javascript去替換已有的文本,達到替換的目的<script

language="javascript1.2">
function test() {
if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf ("****") == 0)){
alert(":)");
a.b.focus();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.