There is a question in Stackoverflow and this one, too. There is a fine solution for jQuery. The only thing we need is window.location.search. Say we have http://domain.com?q=hello&a=good#home, then it takes only ?q=hello&a=good, and leaves #home and the main url. Anchors can be retrieved with hash. Here are all properties of window.location:

Google Chrome provides a fine function: window.location.getParameter:

I like the name of this function. So why not to use it or create this one if a browser doesn’t have it? Well here we go:
if (!window.location.getParameter ) {
window.location.getParameter = function() {};
}
Then I don’t want it to be depending on jQuery, eventhough the odds are big, that jQuery is there. But in all solutions I have seen, there is no usage of jQuery, so why do it as a jQuery extension?
However, we must extract the search part of window.location… I’ll use the solution of Ryan Phelan, but without jQuery (again, why extend jQuery without any usage of it?):
if (!window.location.getParameter ) {
window.location.getParameter = function(key) {
function parseParams() {
var params = {},
e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);
while (e = r.exec(q))
params[d(e[1])] = d(e[2]);
return params;
}
if (!this.queryStringParams)
this.queryStringParams = parseParams();
return this.queryStringParams[key];
};
}
I published this solution on Stackoverflow.
For us Sharepointers
In SharePoint there is actually a built-in javascript function which retrieves the url query parameters: _spGetQueryParam which can be found in init.js:
function _spGetQueryParam(p)
{ULSA13:;
var q=window.location.search.substring(1);
if(q && q.length > 2)
{
var params=q.split("&");
var l=params.length;
for (var i=0;i<l;i++)
{
var pair=params[i].split("=");
if (pair[0].toLowerCase()==p)
return pair[1];
}
}
}
As I posted in an answer on sharepoint.stackexchange.com it can be used like this:
var id = _spGetQueryParam("ID");
var url = "/Forms/AllItems.aspx?FilterField1=look&FilterValue1=" + id;
Like this:
Like Loading...
How do you use this? I don’t understand how to get the url param. Do I write i.ex. parseParams(‘name’) if the URL is http://example.com/?name=bob
This does not work. I am lost.
How do I call this function?