Get Url Parameters


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

Read a page's GET URL variables and return them as an "associative array."

Calling the function while at `example.html?foo=asdf&bar=jkls` sets `map['foo']='asdf'` and `map['bar']='jkls'`


Copy this code and paste it in your HTML
  1. function getUrlVars() {
  2. var map = {};
  3. var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. map[key] = value;
  5. });
  6. return map;
  7. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.