2014-01-10 21 views
0

所以我们都知道,一旦你发布了它们,你不能真正保护你的图像,但它可以挑逗外行人的乐趣。我添加了一个脚本来防止右键单击,并试图随机化有趣的消息...它不工作。随机没有右键单击消息不起作用

脚本:

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

什么我忘了?它看起来应该起作用。当我删除[和]并将其减少到一条消息时,该消息就可以正常工作。当我添加额外的内容并尝试随机发现问题时。

+0

您可以向整个阵列。 – putvande

回答

2

您正在提醒整个阵列。
如果你想拥有你可以不喜欢随机消息:

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

这产生一个随机数出你的阵列中有邮件的数量。

Math.random
Math.floor

+1

谢谢!有效。 – rivenagares