简体   繁体   English

随机没有右键单击消息不起作用

[英]Random No Right-Click Message Not working

So we all know that you cannot truly protect your images once you post them, but its a bit of fun to tease the lay person. 所以我们都知道,一旦你发布你的图像,你就无法真正保护你的图像,但它可以让那个外行人变得有趣。 I added a script to prevent right-clicking and was trying to randomize funny messages... its not working. 我添加了一个脚本,以防止右键单击,并试图随机化有趣的消息......它不起作用。

the script: 剧本:

// 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")

What am I forgetting? 我忘记了什么? It looks like it should work. 它看起来应该有效。 when I remove the [ and ] and reduce it to one message, that message works just fine. 当我删除[和]并将其减少为一条消息时,该消息正常工作。 Its when I add additional and attempt to randomize it that the issues occur. 它当我添加额外的并尝试随机化它发生问题。

You are alerting the whole array. 你警告整个阵列。
If you want to have random message you could do something like: 如果您想要随机消息,您可以执行以下操作:

 var rn = Math.floor(Math.random() * message.length);
 alert(message[rn]);

This generates a random number out of the number of messages you have in the array. 这会在数组中的消息数中生成一个随机数。

Math.random 的Math.random
Math.floor Math.floor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM