javascript Remove item from QueryString

function RemoveQuery(variable) {
    //removes an item from the queryString
    var query = window.location.search.substring(1);
    var vars = query.split("&");//split at & to retrieve pairs
    var URL = "";
 
    //loop through queryString characters
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("="); //split at = to retrieve key/value
        if (pair[0].toString().toLowerCase() != variable.toString().toLowerCase()) {
            if (pair[0].toString().toLowerCase() != 'r') {//remove force refresh (r), as a new one will be appended later
                URL = URL + '&' + pair[0] + '=' + pair[1];//build up new queryString
            }
        }
    }
 
    //add ? prefix
    if (URL.toString().substring(0, 1) == '&') {
        URL = '?' + URL.toString().substring(1, URL.toString().length);
    }
 
    return URL;
}
Removes an item from the QueryString part of a URL.

Updated: Thursday 7th October 2010, 09:34pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.