Back to previous

How to get QueryString using JavaScript

A very handy function to grab any query string using Javascript:

function getQueryString( 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];
}
 

ShareThis

If you think this post is useful, please recommend me at the bottom of the page. ;)

Discussion