你的位置:首页 > Java教程

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


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

 1 //禁止页面内按F5键进行刷新 2 function f_DisableF5Refresh(event) { 3  var e = event || window.event; 4  var keyCode = e.keyCode || e.which; 5  if(keyCode == 116) { 6   if(e.preventDefault) { //非IE 7    e.preventDefault(); 8   } else { //IE 9    e.keyCode = 0;10    e.returnValue = false;11   }12  }13 }14 if(document.addEventListener) {15  document.addEventListener('keydown', f_DisableF5Refresh, false);16 } else {17  document.attachEvent('onkeydown', f_DisableF5Refresh);18 }

 

禁止复制信息内容:

 1 //禁止复制信息内容 2 var returnFalse = function () { 3   return false; 4 }; 5 var content = document.getElementById('newsContent'); 6 content.ondragstart = returnFalse;//IE or FireFox 7 content.oncopy = returnFalse;//IE or FireFox 8 content.onselectstart = returnFalse; //just IE 9 10 document.body.oncontextmenu = returnFalse; //IE or FireFox11 document.body.onkeydown = function (event) {//just IE12   var e = event || window.event;13   var keyCode = e.keyCode || e.which;14   if (keyCode == 65 || keyCode == 88 || e.ctrlKey || e.shiftKey) {//key is a = 65 or x = 8815     e.returnValue = false;16   }17 };