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 } 
  • 相关阅读:
    移位运算符<<与>>
    在线颜色选择器
    CSS鼠标指针cursor样式
    JavaScript实现自定义右键菜单
    如何去掉ul和li前面的小黑点
    转载:利用本地存储实现记录滚动条的位置
    CSS中样式覆盖优先顺序
    断言类
    MQ发送定时消息
    看代码所学3
  • 原文地址:https://www.cnblogs.com/oolnc/p/7691175.html
Copyright © 2011-2022 走看看