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 }