code: function(url, key, value) {
      var queryStrPos = url.indexOf('?');
      var anchorStrPos = url.lastIndexOf('#');
      
      var paramSeparator = '&';
      
      if(queryStrPos < 0) {
          // There's no query string.
          paramSeparator = '?';
      }
      
      if (anchorStrPos > 0) {
          // There's an anchor at the end, we need to insert our parameter before it
          var urlBeforeAnchor = url.substring(0, anchorStrPos);
          var urlAnchor = url.substring(anchorStrPos);
          return urlBeforeAnchor + paramSeparator + key + '=' + value + urlAnchor;
      } else {
          return url + paramSeparator + key + '=' + value;
      }
  }
docs: Simply adds a key=value parameter on to the query string of the URL. Anchors are left intact. If there is no ? query string, one is appended to the end of the URL (or inserted just before the anchor).