---
title: "html 禁止右键功能"
author: "yaoweinan"
date: "2011-03-19T16:52:36Z"
tags: []
categories: ["Web前端"]
slug: "html"
draft: false
lastmod: "2011-03-19T16:52:36Z"
id: 967660
url: "https://ilyon.iteye.com/blog/967660"
---

--  禁止点击鼠标右键的四种方法
<SCRIPT LANGUAGE=JavaScript id=clientEventHandlersJS> 

<!-- 

function document_onmousedown() { 
if (event.button==2) 
{ 
alert("对不起!不能提供复制的功能！"); 
return false; 
} 

} 

function document_onselectstart() { 
alert("对不起！不能提供复制的功能!"); 
return false; 
} 

function document_onkeydown() { 
if(window.event.ctrlKey || window.event.altKey){ 
alert("对不起！不能提供复制的功能！"); 
return false; 
} 
} 

//--> 
</SCRIPT>




再来一个代码，也能实现
加入下面的代码就好咯
<SCRIPT language=JavaScript>
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
oncontextmenu=\'return false\';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu=\'return false\';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
</SCRIPT>




给个简单的

<script language="JavaScript"> 
document.oncontextmenu=new Function("event.returnValue=false;"); //禁止右键功能,单击右键将无任何反应 
document.onselectstart=new Function("event.returnValue=false;"); //禁止先择,也就是无法复制 
</script>