您的位置:首页 > 其它

如何在页面中禁用鼠标右键

2018-03-18 20:40 211 查看
今天意外到了一个外国的网站,这个网站虽然设计的不怎么样,但是他既然不能够按下这个鼠标右键,引起了我的好奇。
所有我就研究了一下,想与大家一起分享var message="Right Click Function Disabled on this Page!"; //按下右键时,所要提示的信息
function clickIE4()
{
//event.button 是用来监视鼠标事件
if (event.button==2) { //1  表示鼠标左键   4  表示鼠标中键     2  表示鼠标右键
alert(message);

return false;
}
}

function clickNS4(e)   //非ie浏览器

{

if (document.layers||document.getElementById&&!document.all)

{   //非ie浏览器 e.keycode == e.which
//非ie浏览器的鼠标事件为  0为左键  1为中键  2为右键
if (e.which==2||e.which==1)

{

alert(message);

return false;

}

}

}

if (document.layers)

{

document.captureEvents(Event.MOUSEDOWN);

document.onmousedown=clickNS4;

}

else if (document.all&&!document.getElementById)

{

document.onmousedown=clickIE4;

}

//此函数为内置函数,来禁用鼠标右键
document.oncontextmenu=new Function("alert(message);return false")

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: