Skip to content

Instantly share code, notes, and snippets.

@boy3vil
Created February 28, 2015 04:13
Show Gist options
  • Select an option

  • Save boy3vil/0f71fa44da9ef868ed69 to your computer and use it in GitHub Desktop.

Select an option

Save boy3vil/0f71fa44da9ef868ed69 to your computer and use it in GitHub Desktop.
jQuery parse parameter string url
alert(url_variable('my_url')['data1']);
//parse parameter string url
function url_variable(url){
var vars = [], hash;
//var url = "../develop/dashboard/?data1=2&data2=4";
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment