Skip to content

Instantly share code, notes, and snippets.

@dre3s
Last active January 18, 2016 16:46
Show Gist options
  • Save dre3s/c25e74622f74de19ca35 to your computer and use it in GitHub Desktop.
Save dre3s/c25e74622f74de19ca35 to your computer and use it in GitHub Desktop.
my.js.querystring

Query Strings Url

Como pegar parâmetros da url
var queryString = {
  getParams: function() {
    return this._getQueryString(window.location);
  },

  _getQueryString: function(url) {
    var query = url.search.substring(1),
        vars = query.split('&'),
        data = {};

    vars.forEach(function(key, i){
      var pair = vars[i].split('=');
      data[pair[0]] = pair[1];
    });

    return data;
  }
}

module.exports = queryString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment