Remove URL parameter from URL and reload the page in JavaScript


Method:
function removeParam(key, sourceURL) {
var rtn = sourceURL.split("?")[0],
param
,
params_arr
= [],
queryString
= (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
if (queryString !== "") {
params_arr
= queryString.split("&");
for (var i = params_arr.length - 1; i >= 0; i -= 1) {
param
= params_arr[i].split("=")[0];
if (param === key) {
params_arr
.splice(i, 1);
}
}
rtn
= rtn + "?" + params_arr.join("&");
}
return rtn;
}

Call: 
var originalURL = "http://yourewebsite.com?id=10&color_id=1";
var alteredURL = removeParam("color_id", originalURL);

output: http://yourewebsite.com?id=10

Here are the some of the book recommendations :

           

Enable GingerCannot connect to Ginger Check your internet connection
or reload the browser
Disable in this text fieldEditEdit in GingerEdit in GingerΓ—

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks