Retrieve URL Parameters with JavaScript

javascript

This is a simplethat makes it easy to get a URL parameter with JavaScript if ever needed.

The only thing you have to do is call '_url_param' function and pass the name of the parameter you want and that is it.

				function _url_param(k)
				{
					p = new Array();
					u = window.location.href;
					q = u.substring(u.indexOf('?') + 1).split('&');
					
					if(u.indexOf('?') === -1)
						return '';
					
					for(v in q){
						s = q[v].split('=');
						p[s[0]] = s[1];
					}
					
					if(!p[k])
						return '';
					
					return p[k];
				}
			

This is a compressed version of this.

				function _url_param(k){p=new Array();u=window.location.href;q=u.substring(u.indexOf('?')+1).split('&');if(u.indexOf('?')===-1)return'';for(v in q){s=q[v].split('=');p[s[0]]=s[1]}if(!p[k])return'';return p[k]}