Created
December 7, 2017 04:37
-
-
Save daothanh/b939241b2b683e0a24afc77184fe571f to your computer and use it in GitHub Desktop.
This file contains 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 buildUrl(url, parameters){ | |
var query = window.location.search.substring(1), vars = query.split('&'), qs = ""; | |
if (vars.length) { | |
for(var j in vars) { | |
if (vars[j] !== "") { | |
var value = vars[j].split("="); | |
if (parameters.hasOwnProperty(value[0]) === false) { | |
parameters[value[0]] = value[1]; | |
} | |
} | |
} | |
} | |
for(var key in parameters) { | |
qs += encodeURIComponent(key) + "=" + encodeURIComponent(parameters[key]) + "&"; | |
} | |
if (qs.length > 0){ | |
qs = qs.substring(0, qs.length-1); //chop off last "&" | |
url = url + "?" + qs; | |
} | |
return url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment