A simple JavaScript function, which parses the url and returns an object(map) with keys being the parameter names and values being parameter values.

function getUrlParameters() {
	var url = document.location.href;
	var parameters = url.substring(url.indexOf("?") + 1);
	parameters = parameters.split("&");
	var parametersObj = {};
	for (var key in parameters) {
		var parameterString = parameters[key];
		parameter = parameterString.split("=");
		parametersObj[parameter[0]] = parameter[1];
	}
	return parametersObj;
}

If there are multiple parameters in the url with the same name, only the last one will be present in the returned object.

Advertisements