Get URL Parameters using jQuery and JavaScript

Most PHP apps use parameters to query data. There are many cases you have to handle these parameters on front-end, hence JavaScript or jQuery is used. Actually, jQuery isn’t necessary in this case. Below are small code snippets which can help you retrieve any parameters in a URL.

Get parameters from current URL:

//if URL contains '?test=true'
var isTest = getCurrentURLParamValue('test');
function getCurrentURLParamValue(param){
    var urlParams =;
    var urlParamsArray = urlParams.split('&');
    for (var i = 0; i < urlParamsArray.length; i++){
        var urlParamName = urlParamsArray[i].split('=');
        if (urlParamName[0] == param){
            return urlParamName[1];

Get parameters from any given URL:

//if URL contains '?test=false&title=A+Test+Title'
var isTest = getURLParamValue('', 'test');
var title = getURLParamValue('', 'title');

function getURLParamValue(url, param){
    var results = new RegExp('[\?&]' + param + '=([^&#]*)').exec(url);	
    if (results != null){
       return decodeURIComponent(results[1]);
    } else{
       return null;