Skip to content

Instantly share code, notes, and snippets.

@leolanese
Created April 10, 2020 04:36
Show Gist options
  • Save leolanese/e7cf996a9cbf3f1cb2c63ec86c151a78 to your computer and use it in GitHub Desktop.
Save leolanese/e7cf996a9cbf3f1cb2c63ec86c151a78 to your computer and use it in GitHub Desktop.
Remove url parameter from url path using fallback for IE and legacy browsers
function removeUrlParameter(url, param) {
if (typeof URLSearchParams !== 'undefined') {
// modern browsers
var r = new URL(url);
r.searchParams.delete(param);
return r.href;
} else {
// IE version
return url.replace(new RegExp('^([^#]*\?)(([^#]*)&)?' + parameter + '(\=[^&#]*)?(&|#|$)' ), '$1$3$5').replace(/^([^#]*)((\?)&|\?(#|$))/,'$1$3$4')
}
}
removeUrlParameter(location.href, 'comp');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment