Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript documentation on getParameterByName?

Tags:

javascript

I can't seem to find any detailed documentation on getParameterByName(). I've searched Mozilla, Google, and here. Am I missing something?

like image 943
Dandy Avatar asked Feb 29 '12 15:02

Dandy


1 Answers

We use this where I work. Similar to ThiefMaster's solution...

function getParameterByName( name ){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}
like image 133
mtwagner Avatar answered Oct 04 '22 23:10

mtwagner