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

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: