Activate Javascript based on random chance

Discussion in 'JavaScript' started by «þ», Dec 3, 2007.

  1. #1
    Apologies for this somewhat odd request, but is there a javascript that would only activate based on chance?

    For example, I want a script that will make a javascript load only 20% of the time on that particular page.

    Thanks for your help!
     
    «þ», Dec 3, 2007 IP
  2. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In your body.onload:

    
    if (Math.random() >= 0.20)
      function();
    
    Code (markup):
     
    James McMurray, Dec 3, 2007 IP