Looking for a JavaScript code that can rewrite links

Discussion in 'JavaScript' started by K.Meier, Sep 16, 2010.

  1. #1
    Hi there,

    I'm only familiar with PHP and my JavaScript knowledge is like zero, but this time I have the need for the following javascript:

    I need a javascript which can search through the html code of the page, find this link http://www.domain.com/all/ads/page-3/terms-word1 word2 word3/ and rewrite it to http://www.domain.de/showcat.php?cat=all&si=word1+word2+word3&sort=1&page=1

    I'm reading JavaScript tutorials about innerHTML already, but I can't seem to find a good start.

    Thanks for the help.
     
    K.Meier, Sep 16, 2010 IP
  2. wab

    wab Member

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    you can use some jquery to do the job:

    
    <html>
      <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
        <script>
           $(document).ready(function(){
                $("a[href='http://www.domain.com/all/ads/page-3/terms-word1 word2 word3/']").attr("href", "http://www.domain.de/showcat.php?cat=all&si=word1+word2+word3&sort=1&page=1");
           });
        </script>
      </head>
      <html>
        old link:http://www.domain.com/all/ads/page-3/terms-word1 word2 word3/ <br /><br />
        <a href="http://www.domain.com/all/ads/page-3/terms-word1 word2 word3/">
          test
        </a>
        
      </html>
    </html>
    
    Code (markup):
     
    wab, Sep 17, 2010 IP