21 November 2012

This function gets URL variables in JavaScript. Current page url parameters will be parsed into array, that will be returned.

Source code viewer
  1. function get_url_variables(url) {
  2. var vars = {};
  3. var parts = decodeURIComponent(url).replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
  4. vars[key] = value;
  5. });
  6. return vars;
  7. }
  8.  
  9. var parameters = get_url_variables(window.location.href);
Programming Language: PHP