If then statement for navigation question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • canderson
    New Member
    • Feb 2008
    • 3

    If then statement for navigation question

    Hi there,
    This is my first time here. I have a beginning understanding of javascript so please bare with me.

    I am running a simple navigation script that goes something like this:

    Code:
    cText += '<p><a href="http://www.mysite.com/welcome.html">Welcome<br>'
    cText += '<br>'
    cText += '</a></p>'
    cText += '<p><a href="http://www.mysite.com/contact.html">Contact<br>'
    cText += '<br>'
    cText += '</a></p>'
    Is there an if/then statement (or other) that could say:

    If the html code has a Welcome link such as:
    Code:
    <a href="http://www.mysite.com/welcome2.html">Welcome</a>
    then change it to
    Code:
    <a href="http://www.mysite.com/welcome.html">Welcome</a>
    Thanks and I hope I've clearly asked my question!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    only for my understanding ... you want all links that have a linktext 'Welcome' to point to 'welcome.html' instead of possibly other welcome-pages?

    kind regards

    Comment

    • canderson
      New Member
      • Feb 2008
      • 3

      #3
      Yes, that is correct.

      Thank you!

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        then have a look at the following example:

        [CODE=javascript]var link_list = document.getEle mentsByTagName( 'a');

        for (var i = 0, node; node = link_list[i]; i++) {
        if (node.innerHTML == 'Welcome') {
        node.href = 'http://www.mysite.com/welcome.html';
        }
        }[/CODE]
        now you could put that in a function and call it when you need it.

        kind regards

        Comment

        • canderson
          New Member
          • Feb 2008
          • 3

          #5
          Thank you very much - I will work with that. This will be a good learning experience for me.

          I appreciate your help!

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            no problems ... post back in case you have further questions ... :)

            kind regards

            Comment

            Working...