Separating URL Params


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. function getUrlParams(url) {
  2. var params = {};
  3.  
  4. url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
  5. params[key] = value;
  6. });
  7.  
  8. return params;
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.