title: Remove a Particular Query string from URL
body: <p>I am trying to create a function to remove a particular querystring and its value from the url . </p>
  
  <p>For eg: 
  if i have a url like </p>
  
  <blockquote>
    <p>var url = www.foo.com/test?name=kevin&amp;gender=Male&amp;id=1234</p>
  </blockquote>
  
  <p>If i pass name -> it should remove the key and value for name. the url should become </p>
  
  <blockquote>
    <p>www.foo.com/test?gender=Male&amp;id=1234</p>
  </blockquote>
  
  <p>i have a Function <code>ReturnRefinedURL(key,url)</code></p>
  
  <p>and i am doing this in the Function </p>
  
  <pre><code>function ReturnRefinedURL(key,url)
  {
  var Value  = getParameterByName(key); // This returns kevin
  var stringToBeRemoved = 'key +'='+ Value+'&amp;'; // string becomes 'name=kevin&amp;'
  return url.replace(stringToBeRemoved, '');
  }
  </code></pre>
  
  <p>//Found this in Google:</p>
  
  <pre><code>function getParameterByName(name) {
      name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
      var regex = new RegExp("[\\?&amp;]" + name + "=([^&amp;#]*)"),
          results = regex.exec(location.search);
      return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }
  </code></pre>
  
  <p>So when i call the method <code>ReturnRefinedURL('name',window.location.href);</code></p>
  
  <p>This works!!!  But looking for a more elegant and fool proof method. <br>
  * This wont work if name parameter is the second one in the query string. (the '&amp;' will still be retained)</p>