Posted By

LucasRinaldi on 08/11/12


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Separating URL Params

 / Published in: JavaScript

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.

  1. function getUrlParams(url) {
  2. var params = {};
  4. url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
  5. params[key] = value;
  6. });
  8. return params;
  9. }

Report this snippet  

You need to login to post a comment.