title: Append query strings through links, buttons, menus etc
body: <p>I have been using this javascript on my Wordpress site for sometime now and it has been working fine until a day or two ago, I did not change anything that would affect this. It still works fine on my test site so I cannot figure out why it stopped working. I am looking for any solution to the problem. Basically, agents are given a unique query string to give so when their customers visit the site, they will get commission. When a visitor goes from page to page or clicks the quote button (going to external portal), the query string passes page to page and to the external portal.
  site.com/?group=agent123 - the script is loading. Firefox error is <em>href is undefined</em>. Chrome shows error regarding <em>indexOf</em>, line noted below fixed the error but did not make the script work... I am not a script writer so I cannot figure it out.</p>
  <pre><code>var index = window.location.href.indexOf('?') 
      if(index != -1){
          var querystring = window.location.href.slice(index + 1)
          var tagA = document.getElementsByTagName('a');
  
      // this next line fixed the error hence allowing other 
      // broken scripts after this to work again but script does not work 
      // for appending the query strings...   
  if (href !== undefined)
              
          for(var i = 0; i &lt; tagA.length; i++){
              var href = tagA[i].getAttribute('href');
  
              href += (href.indexOf('?') != -1)? '&amp;' : '?';
              href += querystring;
  
              tagA[i].setAttribute('href', href);
              
          
          }
      }
  </code></pre>