DanWebb
7/23/2014 - 4:52 AM

Get a variable passed in the url using js

Get a variable passed in the url using js

function getUrlVar(variable) {
  var result = false;
  
  window.location.search.substring(1).split('&').forEach(function(param) {
    if(param.split("=")[0]===variable) result=decodeURI(param.split("=")[1]);
  });
  
  return result;
}
function getUrlVar(variable) {
  return decodeURI((window.location.search.substring(1).split('&').find(function(param) {
      return param.split("=")[0] === variable;
  }) || '=').split("=")[1]);
}