You could do this much better using client side storage. localStorage has good browser support and is easy to implement. Saving a value:
localStorage.setItem( "key", "some value" );
Retrieving key:
var retrievedString = localStorage.getItem( "key" );
The saved values will persist between page navigations, and even after the session ends. More info here
But as far as passing current querys through links, you can override the default behaviour of all <a> tags, and instead run a function that gets the href of the link and the query section of the current page's url, merges them together into a new url and then navigates there. (modified from here)
document.onclick = function (e) {
e = e || window.event;
var element = e.target || e.srcElement;
if (element.tagName == 'A') {
var q = location.href;
window.location.href = element.href + q.substring( q.indexOf( "?" ) );
return false;
}
};