Jaap Vossers' SharePoint Blog

Just another WordPress.com site

Getting query string values in JavaScript

leave a comment »

With the introduction of the new SharePoint 2013 App Model, many SharePoint Developers will have to get their hands dirty writing JavaScript. One operation that is going to be very common is to read query string values from JavaScript. C# Developers are used to things like HttpContext.Current.Request.QueryString[“param1”], but unfortunately it is slightly more complicated to get the same result in JavaScript.

Searching the web for an answer on how to do this in JavaScript yields many different results. I would say that the best suggestions are listed on this popular question on StackOverflow. The most upvoted answer to this StackOverflow question has been improved by James Padolsey which has lead to the following function:

function getParameterByName(name) {

    var match = RegExp('[?&]' + name + '=([^&]*)')

    return match ?
        decodeURIComponent(match[1].replace(/\+/g, ' '))
        : null;


This is my favourite solution as it’s brief, readable, and it works 🙂




Written by jvossers

August 30, 2012 at 11:18 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: