Rotate Html Links

Discussion in 'JavaScript' started by sudduch, Aug 17, 2007.

  1. #1
    Hello Friends,

    I need help in javascript to Rotate the links..say for ex.I have 5 links in my website and I need to vary these 5 links accordingly!!

    Hope u understand my question.

    Regards,
    Suddu
     
    sudduch, Aug 17, 2007 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    meanwhile you wait for a javascript solution

    here a MOST simple php solution
    a tiny script file stored inside the folder that contains small HTML ( or other files ) links from

    I just saw that the original web site no longer exists and the forwarded URL has no such script - if interested I can help u with a copy of mine for free just EMAIL me directly if u wish so


    will randomly select ANY of the files

    I use the same script for my blog banner image - but the script works perfect for any other file extension as well

    the script is called from within the file and location where you want the links ( images ) to be placed
     
    hans, Aug 17, 2007 IP
  3. sudduch

    sudduch Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    How can I achieve the same thing using only html file.

    Regards,
    Suddu
     
    sudduch, Aug 17, 2007 IP
  4. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #4
    emailed you the rotate php script
    if only inserting links - then of course you create files and have only the link part of the CORRECT / validated HTML link-code in each file WITHOUT <head> section of the file.
    best is to place the code within a <div> and give that <div> the desired formating using CSS
     
    hans, Aug 18, 2007 IP
  5. sudduch

    sudduch Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you I get your php script!! But I didn't get the exact output. I want it to be using html & Javascript could you suggest me with appropriate .
     
    sudduch, Aug 19, 2007 IP
  6. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #6
    I am NOT into js
    but since it displays whatever code you have in your random folders - it may as well be used for js - I guess you may have to do your own studying and testing

    for HTML it does a perfect job
     
    hans, Aug 20, 2007 IP
  7. mjamesb

    mjamesb Member

    Messages:
    88
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #7
    Not exactly sure what you are trying to do but this is a basic example of a script that will randomly rotate the contents of a div.

    <body>
    <div id="RotateLink"></div>


    <script language="javascript">
    var links = new Array("link1", "link2", "link3", "link4", "link5");
    var randomnumber=Math.floor(Math.random()*5)
    document.getElementById("RotateLink").innerHTML = links[randomnumber];
    </script>
    </body>
     
    mjamesb, Aug 20, 2007 IP
  8. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #8
    such js scripts certainly work perfect
    disadvantage however is
    each time you add new links for random selection you have to change the script - in an external js script only once - if you have it on the page then on each page where you use this script.

    while in the PHP script you just add links or link groups and have nothing to change in the script itself
     
    hans, Aug 20, 2007 IP