This project has moved and is read-only. For the latest updates, please go here.

It would be convenient if SPGetQueryString accepted an optional parameter

Jun 26, 2013 at 1:50 PM
to use as a source rather than window.location. I regularly have need for parsing a querystring from a link in a list view web part (usually to grab the ID) and what I do now is copy the SPGetQueryString function into my own JavaScript file to make changes.
Jun 26, 2013 at 3:18 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 26, 2013 at 3:19 PM
Seems like a reasonable idea, at least on the surface. The parsing logic ought to work the same if you pass in a URL. Added to my list for the next release.

Jun 26, 2013 at 4:14 PM
The only potential difficulty might be determining the equivalent of "". As I know every link I parse will be an aspx page, I just split the string on ".aspx?". See my implementation below.
function GetQueryString(str) {
        var queryStringVals = {};
        var matches;
        var qs = str.toUpperCase().split('.ASPX?')[1];
        var args = qs.split("&");
        var rxQS = /^([^=]+)=(.*)/i;

        for(var i=0; i < args.length; i++) {
            matches = rxQS.exec(args[i]);
            if(rxQS.test(location.href)) {
                if(matches !== null && matches.length > 2) {
                    queryStringVals[matches[1]] = unescape(matches[2]).replace(/\+/g,' ');
        return queryStringVals;
Jun 27, 2013 at 5:42 PM
Since this would be an unusual usage, do you think it would be reasonably to assume that the ? always splits the query string?