[JS] How to get a querystring value given the key
Suppose you have an URL like this: www.host.com?m=5&lang=it. If you want to retrive the value of lang, you could simply use this function:
function parseURL(url,key)
{
var reQS = new RegExp("[?&]"+key+"=([^&$]*)", "i");
var offset = url.search(reQS);
return ( offset >= 0 ) ? RegExp.$1 : null;
}
// usage
var myKey = parseURL("www.host.com?m=5&lang=it","lang")
Via blog.falafel.com