网页禁用右键实现代码(JavaScript代码)
时间:2021-07-01 10:21:17
帮助过:2人阅读
代码如下:
<script language="javascript">
function disableRightClick(e)
{
var message = "右键禁用...";
if(!document.rightClickDisabled) // initialize
{
if(document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = disableRightClick;
}
else document.oncontextmenu = disableRightClick;
return document.rightClickDisabled = true;
}
if(document.layers || (document.getElementById && !document.all))
{
if (e.which==2||e.which==3)
{
alert(message);
return false;
}
}
else
{
alert(message);
return false;
}
}
disableRightClick();
</script>
使用方法,直接放到<head></head>中即可。