Skip to content

Instantly share code, notes, and snippets.

@stuntbox
Created November 14, 2014 21:30
Show Gist options
  • Select an option

  • Save stuntbox/d492e358f751598ca32b to your computer and use it in GitHub Desktop.

Select an option

Save stuntbox/d492e358f751598ca32b to your computer and use it in GitHub Desktop.

Revisions

  1. stuntbox created this gist Nov 14, 2014.
    22 changes: 22 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /*- Query String Values ------------------------------------------------------*/
    //
    // Retrieves, parses URL query string values into an object using JS.
    // See "JavaScript: The Definitive Guide", 5th ed, p.272, example 14-1.

    var queryStringValues = getQueryStringValues();

    function getQueryStringValues() {
    // var args = new Object();
    var args = {};
    var query = location.search.substring(1);
    var pairs = query.split("&");
    for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf("=");
    if (pos == -1) continue;
    var argName = pairs[i].substring(0, pos);
    var value = pairs[i].substring(pos + 1);
    value = decodeURIComponent(value);
    args[argName] = value;
    }
    return args;
    }