Jake Paris

GET Query Params with Javascript

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

    var q = queryString.replace('?','').split('&');
    q.forEach(function(pair,index){
        var a = pair.split('=');
        if(typeof a[1]==='undefined')
            a.push('');
        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;
    else
        return queries[param];
};

2 comments

Make a Comment

All fields are required. No one will see your email other than me.