0

Let's say I have the following URL addresses:

www.mydomain.com/default.aspx?param1=value1&param2=value2&param3=value3
OR
www.mydomain.com/default.aspx?param2=value2&param1=value1
OR
www.mydomain.com/default.aspx?param3=value3&param1=value1&param2=value2

How can I remove only the part "param1=value1" from those URL addresses with jQuery or Javascript?

Gloria
  • 1,305
  • 5
  • 22
  • 57
  • possible duplicate of [How can I get query string values in JavaScript?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Jay Blanchard Feb 04 '15 at 12:31
  • possible duplicate of [Parse URL with jquery/ javascript?](http://stackoverflow.com/questions/6644654/parse-url-with-jquery-javascript) – fuchs777 Feb 04 '15 at 12:44

2 Answers2

1

try this:-

function RemoveParam(url, p) {
   return url
  .replace(new RegExp('[?&]' + p + '=[^&#]*(#.*)?$'), '$1')
  .replace(new RegExp('([?&])' + p + '=[^&]*&'), '$1');
}

var url='www.mydomain.com/default.aspx?param3=value3&param1=value1&param2=value2'

 alert(RemoveParam(url,'param1'));

Demo

Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
1

try

var url = "www.mydomain.com/default.aspx?param3=value3&param1=value1&param2=value2" 
url = url.replace("&param1=value1", "");
Thomas Baumann
  • 111
  • 1
  • 7
  • I think she wanted to define the parameter name only and don't care about the value. And your solution doesn't work for the first parameter (?param1...) either. – Fenistil Feb 04 '15 at 12:40