您的位置:首页 > Web前端 > JavaScript

js屏蔽浏览器(IE和FireFox)的刷新和右键等功能

2018-03-12 19:20 344 查看
js屏蔽浏览器(IE和FireFox)的刷新和右键等功能
一、js屏蔽浏览器(IE和FireFox)的刷新功能 
document.onkeydown=function() 

if ((window.event.keyCode==116)|| //屏蔽 F5 
(window.event.keyCode==122)|| //屏蔽 F11 
(window.event.shiftKey && window.event.keyCode==121) //shift+F10 


window.event.keyCode=0; 
window.event.returnValue=false; 

if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4 
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); 
return false; 


二、屏蔽右键 
if (window.Event) 
document.captureEvents(Event.MOUSEUP); 
function nocontextmenu(){ 
event.cancelBubble = true 
event.returnValue = false; 
return false; 

function norightclick(e){ 
if (window.Event){ 
  if (e.which == 2 || e.which == 3) 
  return false; 

else 
  if (event.button == 2 || event.button == 3){ 
   event.cancelBubble = true 
   event.returnValue = false; 
   return false; 
  } 

document.oncontextmenu = nocontextmenu; // for IE5+ 
document.onmousedown = norightclick; // for all others 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
function close() //author: sunlei
{
var isIE=document.all?true:false;
if(isIE){//IE浏览器
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY<0 || window.event.altKey){
alert("是关闭而非刷新");
}else{
alert("是刷新而非关闭");
}
}
else{//火狐浏览器
if(document.documentElement.scrollWidth!=0)
alert("是刷新而非关闭");
else
alert("是关闭而非刷新");
}
}
</script>
<body onunload="close();">
</BODY>
</HTML>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: