Get URL parameters

With the following function you can read out the parameters from the currently opened URL:

function getUrlparam (param) {
    var search = window.location.search.substring(1);
    if(search.indexOf('&') > -1) {
        var params = search.split('&');
        for(var i = 0; i < params.length; i++) {
            var key_value = params[i].split('=');
            if(key_value[0] == param) return key_value[1];
       }
    } else {
        var params = search.split('=');
        if(params[0] == param) return params[1];
    }
    return false;
}

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.