Get Url Parameter with Java Script

how to get param "act" value from "httpx://www.example.com?id=2&act=2" ?

here is simple scrypt to get url parameter, return value is an array of params.
function getUrlVars() {
  var vars = {};
  var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; });
  return vars;
}


example :

var pr = getUrlVars()["act"];
if(pr === 2){
 
  // act value = 2
  // do whatever you want

have fun :)

Post a Comment