一個禁止右鍵、選擇、拖曳、清空剪下板、禁止網頁另存新檔的實用JavaScript指令碼

來源:互聯網
上載者:User

 一個禁止右鍵、選擇、拖曳、清空剪下板、禁止網頁另存新檔的JavaScript指令碼。

 

算是比較常用吧。自己不想寫的時候就複製過去,直接使用,不需要其他設定。

  1. <script language="JavaScript">
  2. <!--
  3.  //***********************禁止右鍵***************************
  4. if (window.Event) 
  5.   document.captureEvents(Event.MOUSEUP); 
  6. function nocontextmenu() 
  7. {
  8.  event.cancelBubble = true
  9.  event.returnValue = false;
  10.  return false;
  11. }
  12. function norightclick(e) 
  13. {
  14.  if (window.Event) 
  15.  {
  16.   if (e.which == 2 || e.which == 3)
  17.    return false;
  18.  }
  19.  else
  20.   if (event.button == 2 || event.button == 3)
  21.   {
  22.    event.cancelBubble = true
  23.    event.returnValue = false;
  24.    return false;
  25.   }
  26. }
  27. //************************禁止選擇***************************
  28. function noSelect()
  29. {
  30.     return false;
  31. }
  32. //************************禁止拖曳***************************
  33. function noDragstart()
  34. {
  35.   return false; 
  36. }
  37. //************************清空剪下板*************************
  38.  function keyDown()
  39.  {
  40.   var iekey = event.keyCode; 
  41.   //alert(iekey);
  42.     if(iekey == 42)
  43.     {
  44.     //window.clipboardData.setData('img','')
  45.     
  46.     window.clipboardData.clearData();
  47.     }
  48.  } 
  49. //-->
  50. </script>
  51. <!--禁止網頁另存新檔-->
  52. <noscript> <iframe src="*.htm"></iframe> </noscript>
  53. <!--禁止網頁另存新檔-->
  54. <noscript> <iframe src="*.htm"></iframe> </noscript><SCRIPT language=JavaScript>
  55.   document.oncontextmenu = nocontextmenu;
  56.   document.onmousedown = norightclick;
  57.   document.ondragstart = noDragstart;
  58.   document.onselectstart = noSelect;
  59.   document.onselect = document.selection.empty();
  60.   document.onkeydown = keyDown;
  61. </SCRIPT>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.