JavaScript method to get the url table of all parameter keys

  • 2020-05-17 04:50:31
  • OfStack

The example in this article shows how JavaScript can obtain the key value table of all parameters of url. Share with you for your reference. The specific implementation method is as follows:


function getUrlVars() {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for (var i = 0; i < hashes.length; i++) {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}

I hope this article has been helpful to your javascript programming.


Related articles: