zoukankan      html  css  js  c++  java
  • 在界面上的一些禁用操作,禁用页面后退、复制、粘贴等

    1.禁用Enter键表单自动提交

     1 document.onkeydown = function(event) {  
     2     var target, code, tag;  
     3     if (!event) {  
     4         event = window.event; //针对ie浏览器  
     5         target = event.srcElement;  
     6         code = event.keyCode;  
     7         if (code == 13) {  
     8             tag = target.tagName;  
     9             if (tag == "TEXTAREA") { return true; }  
    10             else { return false; }  
    11         }  
    12     }  
    13     else {  
    14        target = event.target; //针对遵循w3c标准的浏览器,如Firefox  
    15         code = event.keyCode;  
    16         if (code == 13) {  
    17             tag = target.tagName;  
    18             if (tag == "INPUT") { return false; }  
    19             else { return true; }  
    20         }  
    21     }  
    22 }; 

    2.防止页面后退

    1 history.pushState(null, null, document.URL);
    2 window.addEventListener('popstate', function () {
    3        history.pushState(null, null, document.URL);
    4 });

    3.禁止鼠标拖动

    1 document.ondragstart=function(){
    2     return false;
    3 }

    4.禁止鼠标右键菜单

    1 document.onselectstart = function(){
    2     return false;
    3 }

    5.禁止鼠标复制

    1 document.oncopy = function(){
    2     return false;
    3 }

    6.禁止键盘复制、粘贴

     1 document.onkeydown = function(){
     2     if(event.ctrlKey){
     3         return false;
     4     }
     5     if(event.altlKey){
     6         return false;
     7     }
     8     /* if(event.shiftKey){//email与登录需要
     9         return false;
    10     }  */
    11 } 
  • 相关阅读:
    53. Maximum Subarray
    64. Minimum Path Sum
    28. Implement strStr()
    26. Remove Duplicates from Sorted Array
    21. Merge Two Sorted Lists
    14. Longest Common Prefix
    7. Reverse Integer
    412. Fizz Buzz
    linux_修改域名(centos)
    linux_redis常用数据类型操作
  • 原文地址:https://www.cnblogs.com/oolnc/p/7691175.html
Copyright © 2011-2022 走看看