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
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    changing href for all <a> tags on the webpage

    Hi ,

    I want to change the href for all the <a> tags once the page has full loaded.
    Is there any way to do it.

    Regards
    Manjeet

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    yes, is the simple answer.
    What you want to change them to will depend how exactly it's done, but the start point regardless will be something like:
    Code:
    window.onload = function() {
      var links = document.getElementsByTagName('a');
      for(i=0;i<links.length;i++) {
        links[i].href='http://www.google.com';
      }
    }
    I'm assuming that changing all the links on a page to the same thing isn't what you want to do...it would be rather pointless...but instead, you want to add something to the end of all the urls?
    Code:
    links[i].href+='?referrer=1234';
    if your links might already have a querystring (the ? and everything after it) then you won't want the 2nd ? added, but I'm sure you can work that out

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks very much for the quick reply.
    I want to change some part of the url

    Regards
    Manjeet

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to replace the url http://localhost/global/en/homepage.htm by
    http://localhost/ae/ar/homepage.htm

    i.e. to replace global/en by ae/ar

    When I read the links[i] array it does not match the string due to /

    Please suggest some method

    Regards
    Manjeet


  •  

    Posting Permissions

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