How to get query parameters of a URL


Problem

todo



Solution

function getUrlParameter() {
   var parameters = window.location.search.substr(1);
   var decode = function(input) { return decodeURIComponent(input.replace(/\+/g, '')); };
   var pattern = /([^&=]+)=?([^&]*)/g;
   var match;
   var urlParams = {};

   while((match = pattern.exec(parameters)) !== null) {
      urlParams[decode(match[1])] = decode(match[2]);
   }

   return urlParams;
}

Comments




Please sign-in to post a comment