所以我们都知道,一旦发布图像,您就无法真正保护它们,但取笑外行人还是很有趣的。我添加了一个脚本来防止右键单击,并试图随机化有趣的消息......它不起作用。
脚本:
// BACKGROUND IMAGES
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
// no right click
var message=["That doesn't belong to you! Put the mouse down and no one gets hurt!";
"Oh, you again. We of the internet have chosen to defy you!";
"How would you like it if I walked into your house and tried to help myself to your furniture?";
"Hey that tickles!"
"Thief! You are being directed to the... nah just kidding. Enjoy!"]
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
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")
我忘记了什么?看起来应该可以。当我删除 [ 和 ] 并将其减少为一条消息时,该消息工作得很好。当我添加额外的内容并尝试将其随机化时,就会出现问题。
最佳答案
您正在向整个阵列发出警报。
如果您想要随机消息,您可以执行以下操作:
var rn = Math.floor(Math.random() * message.length);
alert(message[rn]);
这会根据数组中的消息数生成一个随机数。
关于javascript - 随机无右键单击消息不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21053224/