With javascript how can I add a query string parameter to the url if not present or if it present, update the current value? I am using jquery for my client side development
To give an code example for modifying window.location.search
as suggested by Gal and tradyblix:
var qs = window.location.search || "?";
var param = key + "=" + value; // remember to URI encode your parameters
if (qs.length > 1) {
// more than just the question mark, so append with ampersand
qs = qs + "&";
}
qs = qs + param;
window.location.search = qs;