---
title: "JS禁止右击菜单"
author: "dingjun1"
date: "2008-08-13T15:25:31Z"
tags: []
slug: "js"
draft: false
lastmod: "2008-08-13T15:25:31Z"
id: 227556
url: "https://dingjun1.iteye.com/blog/227556"
---

```javascript


function key(){
if(event.shiftKey){
window.close();}
//禁止Shift
if(event.altKey){
window.close();}
//禁止Alt
if(event.ctrlKey){
window.close();}
//禁止Ctrl
return false;}
document.onkeydown=key;



function nocontextmenu(){
	//alert("a");
	try{
	   event.cancelBubble = true
	   event.returnValue = false;
	}catch(e){

	}
	return false;
}

function norightclick(){
  if (event.button == 2 || event.button == 3){
	//alert("a");
	try{
	   event.cancelBubble = true
	   event.returnValue = false;
	}catch(e){

	}	
	return false;
   }
}


document.oncontextmenu = nocontextmenu;  // for IE5+
document.onmousedown = norightclick;  // for all others

document.onselectstart = function(){
	return false;
}
document.ondragstart =  function(){
	return false;
}

```