Skip to content

Instantly share code, notes, and snippets.

@gustavo-rodrigues-dev
Last active December 21, 2015 03:48
Show Gist options
  • Save gustavo-rodrigues-dev/6244753 to your computer and use it in GitHub Desktop.
Save gustavo-rodrigues-dev/6244753 to your computer and use it in GitHub Desktop.
Função que converte os dados passados via GET para um objeto
/**
* @return object getUrlData
*/
function getUrlData(callback){
var _default = {
typeData : {},
basePath : window.location.pathname
},
base = window.location,
local = base.href.replace(base.origin+_default.basePath, '').split(/[?,&,#]/),
dados = _default.typeData;
for(var x in local){
if(local != undefined){
var bit = local[x].split('=');
if(bit[0] != ''){
dados[bit[0]] = bit[1];
}
}
}
if (typeof callback == 'function') {
return callback(dados);
}
return dados;
}
function getUrlData(e){var t={typeData:{},basePath:window.location.pathname},n=window.location,r=n.href.replace(n.origin+t.basePath,"").split(/[?,&,#]/),i=t.typeData;for(var s in r){if(r!=undefined){var o=r[s].split("=");if(o[0]!=""){i[o[0]]=o[1]}}}if(typeof e=="function"){return e(i)}return i}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment