Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Random Link

  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Link

    ok there the code so far I was wondering if someone could help me I want to add another link in there there is the nhl one the tsn one , and I want one for www.espn.com. any help would be appreciated thanks in advance


    <html>
    <body>

    <script type="text/javascript">
    var r=Math.random()
    if (r>0.5)
    {
    document.write("<a href='http://www.nhl.com'>NHL</a>")
    }
    else
    {
    document.write("<a href='http://www.tsn.com'>TSN</a>")
    }
    </script>

    </body>
    </html>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    var mylinks = new Array()
    mylinks[0] = "http://www.nhl.com"
    mylinks[1] = "http://www.tsn.com"
    mylinks[2] = "http://www.espn.com"
    
    var mytext = new Array()
    mytext[0] = "NHL"
    mytext[1] = "TSN"
    mytext[2] = "ESPN"
    
    function setLink(){
    var r= parseInt(Math.random() * 3);
    document.getElementById('thelink').href = mylinks[r];
    document.getElementById('thelink').firstChild.nodeValue = mytext[r];
    }
    window.onload = setLink;
    </script>
    </head>
    
    <body>
    <a href="http://www.nhl.com" id="thelink">NHL</a>
    </body>
    </html>
    I did it this way that way just in case the use has js disabled they will still see a good link rather than a useless link.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <html>
    <body>
    <script type="text/javascript">
    var r=Math.random();
    if (r<0.33) { document.write("<a href='http://www.nhl.com'>NHL</a>"); }
    else if (r>0.66) { document.write("<a href='http://www.espn.com'>ESPN</a>"); }
    else { document.write("<a href='http://www.tsn.com'>TSN</a>"); }
    </script>
    </body>
    </html>
    - NS 666
    .net DEVILoper

  • #4
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok thanks a lot both of them helped me, I willl ikely go with the first one incase the javascript is disalbed thanks again


  •  

    Posting Permissions

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