Return to Snippet

Revision: 41949
at February 25, 2011 05:28 by agdm


Initial Code
var map = {};
function getUrlVars() {
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		map[key] = value;
	});
	return map;
}

getUrlVars();

console.log(map.param1);
console.log(map.param2);

Initial URL

                                

Initial Description
given a url:
>`http://www.someurl.com/page.html?param1=foo&param2=bar`  

You can use map.param1 outside of the function such as:  
>`$('#some_hidden_field').val(map.param1);`

Initial Title
mapping of url parameters

Initial Tags
url, javascript

Initial Language
JavaScript