之前有一個(gè)客戶(hù)希望網(wǎng)站的頁(yè)面禁用右鍵的點(diǎn)擊,希望防止圖片被下載(其實(shí)感覺(jué)沒(méi)什么必要,懂一點(diǎn)網(wǎng)站知識(shí)的人還是可以輕易下載的),下面是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("操作錯(cuò)誤.或許是您按錯(cuò)了按鍵!"); } }
else if (document.all){
if (event.keyCode==hotkey&&travel){ alert("操作錯(cuò)誤.或許是您按錯(cuò)了按鍵!"); }}
}
document.onkeydown=gogo