中山php|最优网络中山做网站 中山php建站

最优良人

2011/08/06 at 11:26

禁止页面使用右键的js代码

之前有一个客户希望网站的页面禁用右键的点击,希望防止图片被下载(其实感觉没什么必要,懂一点网站知识的人还是可以轻易下载的),下面是js禁止右键的代码:

function click(e) {
if (document.all) {
if (event.button==1||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;")

var travel=true
var hotkey=17 /* hotkey即为热键的键值,是ASII码,这里99代表c键 */
if (document.layers)
document.captureEvents(Event.KEYDOWN)
function gogo(e)
{ if (document.layers) {
if (e.which==hotkey&&travel){
alert("操作错误.或许是您按错了按键!"); } }
else if (document.all){
if (event.keyCode==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); }}
}

document.onkeydown=gogo

标签:
-