我们在浏览网页时,常常会遇到鼠标在当前网页无法打开右键菜单,那这样的效果是如何做到的呢?快来运行下面的代码效果你就明白了,效果不错。
我们在浏览网页时,常常会遇到鼠标在当前网页无法打开右键菜单,那这样的效果是如何做到的呢?快
来运行下面的代码效果你就明白了,效果不错。
[sourcecode language="html"]
有什么问题请到评论中发表<br>
<!-- http://www.bestchao.com/ -->
<!-- http://www.bestchao.com/ -->
<!--把下列代码放到<body>区域中-->
<script language="JavaScript">
<!--
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
//-->
</script>
[/sourcecode]