wemaycode
6/7/2017 - 8:12 PM

get querystring in JS

get querystring in JS

// USAGE: getQueryString('qs');
// Param is the name of the querystring to check for, i.e. http://www.website.com/?qs=somelabel
// This will return false if it doesn't exist, or the value, i.e. "somelabel," if it does

function getQueryString(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return (false);
}