efficient way to get querystring variables via javascript

Just used this great snippet in a jquery script at a customer: http://snipplr.com/view/799/get-url-variables/

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&#91;i&#93;.split('=');
  vars.push(hash&#91;0&#93;);
  vars&#91;hash&#91;0&#93;&#93; = hash&#91;1&#93;;
}
return vars;
}
&#91;/code&#93;

<strong>How do you use this?</strong>
Well, just put this in your script:


getUrlVars()["QuerystringVariable"];

This will get you the value that is in the querystring for that variable.

Example: www.balestra.be?name=marijn
If I write:

Alert(getUrlVars()["name"];

Then I will get a messagebox popped up that displays “marijn”
This comes in handy when you have to get a few variables out of the querystring !

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.