Tuesday, May 19, 2009

Javascript Get Param From URL

some simple but usefull function 

function getParam( 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 results[1].replace(/\%20/g, " ");
 }
} 

No comments: