Need help with this link script.

Discussion in 'JavaScript' started by Jen-, Oct 17, 2006.

  1. #1
    Hello, I found a link script I like but I would like the link to show up as a link instead of an http address. The javascript rotates the link http: address daily. How can I make it look like a link like this web page name

    instead of this: http://www.google.com?

    Heres the all the code. For web page

    <BODY onload="changing();"><a href="#" id="url"></a>

    For external.js
    arr = new Array(
    ["http://www.google.com/"],
    ["http://www.google.com/"]// no comma at the end of last index
    );

    now = new Date()
    nowDate = now.getDate()

    function changing(){

    if(nowDate > arr.length) { return; }


    document.getElementById("url").href = arr[nowDate-1][0];
    document.getElementById("url").appendChild(document.createTextNode(arr[nowDate-1][0]));
    }

    Please let me know, thank you very much, Jen :rolleyes:
     
    Jen-, Oct 17, 2006 IP
  2. Revamped Solutions

    Revamped Solutions Active Member

    Messages:
    1,347
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    80
    #2
    <a href="http://www.google.com">LinkName</a>
     
    Revamped Solutions, Oct 18, 2006 IP
  3. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks alot, it didn't work. I put your link inside the brackets and quotation marks like this with no luck.

    ["<a href='http://www.google.com'>LinkName</a>"],

    All it did was put all of it on the page instead of just "LinkName."
     
    Jen-, Oct 18, 2006 IP
  4. Revamped Solutions

    Revamped Solutions Active Member

    Messages:
    1,347
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Get rid of brackets. so it would be....

    just <a href="http://..... etc.

    Try that.
     
    Revamped Solutions, Oct 18, 2006 IP
  5. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nope that didn't work either so I tried this
    "<a href='http://www.google.com'>LinkName</a>",

    Still no luck but thanks for the help. Anyone know?
     
    Jen-, Oct 18, 2006 IP
  6. BurgerKing

    BurgerKing Active Member

    Messages:
    397
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Hi,

    Try this for the whole script.

    
    <script type='text/javascript'>
    arr = new Array(
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"],
    ["Go to Google"],["http://www.google.com"]);
    
    now = new Date();
    nowDate = now.getDate();
    
    function changing(){
    
    if (nowDate*2 > arr.length) 
    	return;
    
    document.getElementById("url").href = arr[nowDate*2-1][0];
    document.getElementById("url").appendChild(document.createTextNode(arr[nowDate*2-2][0]));
    }
    </script>
    
    <BODY onload="changing();">
    
    <a href="#" id="url"></a>
    
    </body>
    
    Code (markup):
    The script changes the urls everyday, so you need to have as many lines of:
    ["Go to Google"],["http://www.google.com"],
    Code (markup):
    as there are days in a month.

    Just change the
    ["Go to Google"],["http://www.google.com"],
    Code (markup):
    lines to different values to have different urls appear.

    Cheers.
     
    BurgerKing, Oct 18, 2006 IP
  7. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thats it! Burger, thank you very, very, very, much!! Thank you too Revamped! Jen
     
    Jen-, Oct 18, 2006 IP