Question is that you want to remove certain variables from query string.. use the following sample code and see if this solves your problem.
I have not tested this so please fix the compiling errors if any.
var qParams; (window.onpopstate = function () { var match, pl = /\+/g, // Regex for replacing addition symbol with a space search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, query = window.location.search.substring(1); qParams = {}; while (match = search.exec(query)) qParams[decode(match[1])] = decode(match[2]); })(); // ?st=nc&leadsource=events&product=generic&vendor=abc&vanity_url=example.com-ncevents qParams = { st: "...", vendor: "..", leadsource: "...", product: "...", vanity_url: "..." } // delete all the params you want to delete delete qParams.st; delete qParams.vendor; //if native javascript then use serialize = function(obj, prefix) { var str = []; for(var p in obj) { if (obj.hasOwnProperty(p)) { var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v)); } } return str.join("&"); } //or from Jquery use: var str = jQuery.param( qParams );