$().SPServices.SPGetQueryString drops RealSource QueryString

Apr 28, 2010 at 12:35 PM
Edited Apr 28, 2010 at 12:56 PM

I suggest the following implementation:

    // Get the Query String values and split them out into the queryStringVals array
    $.fn.SPServices.SPGetQueryString = function() {
        var queryStringVals = new Object();
        var qs = location.search.substring(1, location.search.length);
        var args = qs.split("&");
        for (var i = 0; i < args.length; i++) {
            var matches = /^([^=]+)=(.+)/i.exec(args[i]);
            //var nameVal = args[i].split("=");
            //var temp = unescape(nameVal[1]).split('+');
            //nameVal[1] = temp.join(' ');
            if (matches.length > 0)
                queryStringVals[matches[1]] = unescape(matches[2]).replace('+',' ');
        return queryStringVals;

Apr 28, 2010 at 12:50 PM

Can you add an explanation about what the goal is here? Regex drives me battty.


Apr 28, 2010 at 12:56 PM
Edited Apr 28, 2010 at 2:04 PM


Previously that function split the querystring first by & getting the key-value pairs then each of those pairs by =. But if one of those was like Source=http://site/blablabla/Form.aspx?Param=Value, the function would return only  the highlighted portion as the value for Source. If you use regex with capturing groups, that error can be avoided. The first group captures anything before the first = and the second captures the rest of it i.e. the param value unabridged.

Apr 28, 2010 at 1:03 PM

Got it.  That certainly makes sense.  I'll try the change and get it into the next release.


Apr 28, 2010 at 1:06 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.