Return to Snippet

Revision: 58959
at August 15, 2012 02:57 by LucasRinaldi


Updated Code
function getUrlParams(url) {
  var params = {};

  url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
    params[key] = value;
  });

  return params;
}

Revision: 58958
at August 11, 2012 04:41 by LucasRinaldi


Updated Code
function getUrlParams(url) {
  var params = {};

  //find a way to make this code work to both, all the URL or just the params part...
  url.replace(/[?&]*([^=&]+)=([^&]*)/gi, function(str, key, value) {
    params[key] = value;
  });

  return params;
}

Revision: 58957
at August 11, 2012 02:39 by LucasRinaldi


Initial Code
function getUrlParams(url) {
  var params = {};

  url.replace(/[?&]*([^=&]+)=([^&]*)/gi, function(str, key, value) {
    params[key] = value;
  });

  return params;
}

Initial URL


Initial Description
It's a simple function to get the URL params, you can send the URL within the method parameters or you can use 'window.location.href' to get the actual URL.

Obs: This only works for all the URL, if you just want to send the params (after the '?'),  you have to send a '?' before the params.

Initial Title
Separating URL Params

Initial Tags


Initial Language
JavaScript