Last active
January 26, 2016 20:02
-
-
Save patricksimpson/b0474ca612b33814fc8a to your computer and use it in GitHub Desktop.
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
var removeURLParam = function (url, parameter) { | |
var fragment = url.split('#'), | |
urlparts= fragment[0].split('?'), | |
urlBase = '', | |
queryString = '', | |
prefix = '', | |
pars = null, | |
i = 0; | |
if (urlparts.length>=2) | |
{ | |
urlBase = urlparts.shift(); //get first part, and remove from array | |
queryString = urlparts.join('?'); //join it back up | |
prefix = encodeURIComponent(parameter)+'='; | |
pars = queryString.split(/[&;]/g); | |
for (i= pars.length; i-->0;) { //reverse iteration as may be destructive | |
if (pars[i].lastIndexOf(prefix, 0)!==-1) { //idiom for string.startsWith | |
pars.splice(i, 1); | |
} | |
} | |
url = urlBase+'?'+pars.join('&'); | |
if (fragment[1]) { | |
url += '#' + fragment[1]; | |
} | |
} | |
return url; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment