Jake Paris

GET Query Params with Javascript

Update April 2018

Sigh, the things we learn as we go… This is actually way easier than I made it before. In fact, it’s so easy it doesn’t really need these wrapper functions around the URLSearchParams() family of things. However in the interest of making a transition from the earlier code, here you are:

var getQueryStringValue = function(param){
    var queries = new URLSearchParams( window.location.search );
    return queries.get( param );

…Original Post

var parseQueryParameters = function(){
    var queryString = window.location.search;
    var queries = {};
        return queries;

    var q = queryString.replace('?','').split('&');
        var a = pair.split('=');
        if(typeof a[1]==='undefined')
        queries[a[0]] = a[1];
    return queries;
var getQueryStringValue = function(param){
    if(typeof queries === 'undefined')
        var queries = parseQueryParameters();
    if(typeof queries[param] == 'undefined')
        return false;
        return queries[param];

2 responses to “GET Query Params with Javascript”

Leave a Reply

Your email address will not be published. Required fields are marked *