Created
April 10, 2020 04:36
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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