Skip to content

Instantly share code, notes, and snippets.

@neopablix
Created February 15, 2017 17:16
Show Gist options
  • Save neopablix/b774a132408c4eebf3c1d15456b69b87 to your computer and use it in GitHub Desktop.
Save neopablix/b774a132408c4eebf3c1d15456b69b87 to your computer and use it in GitHub Desktop.
function replaceQueryParam(param, newval, search) {
var regex = new RegExp("([?;&])" + param + "[^&;]*[;&]?");
var query = search.replace(regex, "$1").replace(/&$/, '');
return (query.length > 2 ? query + "&" : "?") + (newval ? param + "=" + newval : '');
}
var str = window.location.search;
str = replaceQueryParam('lat', gValue.latitude, str);
str = replaceQueryParam('lng', gValue.longitude, str);
window.location = window.location.pathname + str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment