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 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question javascript request to an always index to addys

    hello,
    ok i was wondering if there is a javascript out there that can put an index to all html's out addies for example in my html i have many out going html's such as href="http://www.website.com/" and mabe later in the html i have a different href= "http://www.website.org/ what i want to do is put a ?randtour.php?ref=mycode&pps=num at the end of all the html's when the go out but not have to type them all out , i hav alot links on one webpage but i really don't want to have to go thru all of them and type in the ?nameof.php?ref=mycode&pps=num at the end of them all ok like i can have

    <IMG alt=[IMG] src="icons/image2.gif"> <A href="http://www.website.com/1/name1/descript/">name of web</A> 10-Feb-2002 11:18 28k
    <IMG alt=[IMG] src="icons/image2.gif"> <A href="http://www.website.com/1/name2/descript/">name of web</A> 10-Feb-2002 11:18 35k

    so when they click on it, it will read on there address bar http://www.website.com/1/name1/descr...ameof.php?ref=mycode&pps=num can any one help i'm also looking for some thing similar like having the javascript put the http://www.website.com/ at the biggining and the ?nameof.php?ref=mycode&pps=num at the end so all i have to write the middle part like href="1/name1/descript/" and it will come out like http://www.website.com/1/name1/descr...ameof.php?ref=mycode&pps=num
    any suggestion or ref to a javascript that i can use cause i want to have the javascript as a seperet file "name.js" so if some one selects at the view/source and only see's 1/name1/descript/ so they can't use it to jump thru my website
    thanks in advance

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    You'd be much better served with a stream editor like sed to text replacements.

    The only way to do this in JavaScript without having to type everything out is to loop over all a elements ( getElementsByTagName("a") ) and check to see if the href contains your domain and if not replace the href with what you want.

    Code:
    document.onload = function()
    {
      var hrefs = document.getElementsByTagName("a");
    
      for (var i = hrefs.length - 1; i>=0; --i)
      {
         if (hrefs[i].href.lastIndexOf("www.mydomain.com") == -1)
         {
             if (hrefs[i].href.lastIndexOf("?") == -1
             {
               hrefs[i].href += "&arg1=5&arg2=6";
              }
              else
              {
                hrefs[i].href += "?arg1=5&arg2=6";
              }
          }
      }
    }

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Most of my web outs have my domain on them there are only a few. most of my out addies have http://www.mydomain.com/ and then my directories like
    1/name1/descript/, 1/name2/descript/, 2/name1/descript/, 3/name3/descript1/ etc. but i want to put the ?nameof.php?ref=mycode&pps=num at the end of all of them without typing them out +tag+ 3/name3/descript1/ +U+ like tag=http://www.mydomain.com/ & u=?nameof.php?ref=mycode&pps=num as for the other domain addies all i need is the ?nameof.php?ref=mycode&pps=num at the end of it.

    For right now I'm just looking for the +U+ (?nameof.php?ref=mycode&pps=num) thing at the end of all the addies. i need the javascript and html edit to make this work.

    Thank You very much for your input.


  •  

    Posting Permissions

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