Skip to content

Instantly share code, notes, and snippets.

@mrroot5
Last active February 1, 2017 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrroot5/e6fe825b5c5df8bd488d to your computer and use it in GitHub Desktop.
Save mrroot5/e6fe825b5c5df8bd488d to your computer and use it in GitHub Desktop.
URL to array, convierte el query de una url a un array. Devuelve los parámetros de URL en un array. From http://stackoverflow.com/questions/4297765/make-a-javascript-array-from-url
function urlToArray(url = '') {
var request = {},
pairs,
i,
pair;
if (url === '') {
url = window.location;
}
pairs = url.substring(url.indexOf('?') + 1).split('&')
for (i = 0; i < pairs.length; i++) {
pair = pairs[i].split('=');
request[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return request;
}
var fullURL = urlToArray(window.location);
// Same result
var queryURL = urlToArray(window.location.search);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment