Fetching URL Parameter with JavaScript

With this code you can fetch all parameters from the URL. The function will return a map with all key & value pairs.


function get_url_parameters(){
  query = window.location.search.substring(1)
  vars = query.split("&");
  hash = new Array()
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    hash[pair[0]] = pair[1]
  }
  return hash
}

One thought on “Fetching URL Parameter with JavaScript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s