Return to Snippet

Revision: 49721
at July 28, 2011 17:23 by a1ias


Initial Code
function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

Initial URL


Initial Description
Usage:
Let's say we have an url: http://primera.vremenno.net?foo=yes&bar=no

var hash = getUrlVars();
alert(hash['foo']); // returns 'yes'
alert(hash['bar']); // returns 'no'

Initial Title
Get URL parameters using Javascript

Initial Tags
url

Initial Language
JavaScript