您所在的位置:小祥子 » 编程 » JavaScript » 正文

禁止页面内按F5键进行刷新(扩展知识:禁止复制信息内容)

时间:2015-05-28 编辑:KenmuHuang 来源:本站整理

禁止页面内按F5键进行刷新:

 //禁止页面内按F5键进行刷新
 function f_DisableF5Refresh(event) {
   var e = event || window.event;
   var keyCode = e.keyCode || e.which;
   if(keyCode == 116) {
     if(e.preventDefault) { //非IE
       e.preventDefault();
     } else { //IE
       e.keyCode = 0;
       e.returnValue = false;
     }
   }
 }
 if(document.addEventListener) {
   document.addEventListener('keydown', f_DisableF5Refresh, false);
 } else {
   document.attachEvent('onkeydown', f_DisableF5Refresh);
 }

禁止复制信息内容:

 //禁止复制信息内容
 var returnFalse = function () {
     return false;
 };
 var content = document.getElementById('newsContent');
 content.ondragstart = returnFalse;//IE or FireFox
 content.oncopy = returnFalse;//IE or FireFox
 content.onselectstart = returnFalse; //just IE
  
 document.body.oncontextmenu = returnFalse; //IE or FireFox
 document.body.onkeydown = function (event) {//just IE
     var e = event || window.event;
     var keyCode = e.keyCode || e.which;
     if (keyCode == 65 || keyCode == 88 || e.ctrlKey || e.shiftKey) {//key is a = 65 or x = 88
         e.returnValue = false;
     }
 };
关键词:页面 禁止 内容