Skip to content

Instantly share code, notes, and snippets.

@deiu
Created June 14, 2016 18:58
Show Gist options
  • Select an option

  • Save deiu/6bc7e3cfad71b5c3b8220b52d387513f to your computer and use it in GitHub Desktop.

Select an option

Save deiu/6bc7e3cfad71b5c3b8220b52d387513f to your computer and use it in GitHub Desktop.

Revisions

  1. Andrei created this gist Jun 14, 2016.
    15 changes: 15 additions & 0 deletions queryVals.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // Map URL query items to their values
    // e.g. ?referrer=https... -> queryVals[referrer] returns 'https...'
    var queryVals = (function (a) {
    if (a === '') return {}
    var b = {}
    for (var i = 0; i < a.length; ++i) {
    var p = a[i].split('=', 2)
    if (p.length === 1) {
    b[p[0]] = ''
    } else {
    b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' '))
    }
    }
    return b
    })(window.location.search.substr(1).split('&'))