Results 1 to 2 of 2

Thread: random url redirect

  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default random url redirect

    I'm new to java script and looking for a way to (automatically) and randomly redirect a user to one of a list of urls after going to the redirect page.

    eg.

    user is sent to /redirect.htm

    instantly then sent to either page1 page 2 or page 3 randomly (or if possible based off a percentage)

    so page1 (30% of the time); page 2 (50%); page 3 (20%)

    any help would be greatly appreciated

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,991
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    (function(n){
     var pages = ['page1.htm', 'page2.htm', 'page3.htm'];
     n = n < 3? 0 : n < 8? 1 : 2;
     window.location.replace(pages[n]);
    })(Math.floor(Math.random() * 10));
    </script>
    </head>
    <body>
    
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •