- ·上一篇文章:mui.ajax提交到PHP服务端出现500错误的解决方法
- ·下一篇文章:jquery判断鼠标按下去的是左键还是右键
屏蔽右键代码兼容IE,google,firefox,opera等常见浏览器
网上找了这么多屏蔽页面上右键代码,都不能完全兼容所有浏览器,我将几个代码综合了一下,实现了兼容IE,google,firefox,opera等常见浏览器的屏蔽右键的代码,代码如下,请按注释要求放到页面相应的地方即可
以下这段代码放到<
head>
<
/head>
中,这段代码主要用来屏蔽除火狐浏览器外的浏览器右键代码
<
script>
//禁止右键
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>
以下代码放到页面<
body>
<
/body>
中,这段主要屏蔽火狐浏览器右键代码
<
script>
 
 
document.oncontextmenu = function()
{return false
}
<
/script>
屏蔽右键代码兼容IE,google,firefox,opera等常见浏览器