javascript - Trying to redirect to the same page but with querystring value -
i want redirect same page, add querystring values. if there querystring value, want strip out , add new one. my code isn't working currently, not sure why: var url = window.location.href; if(url.indexof("?") > 0) { url = url.substring(0, url.indexof("?")); } else { url += "?joined=true"; } window.location.replace(url); the problem you're not adding new query string when strip off old one, in else clause when there's no old query string. take addition out of else , time. var url = window.location.href; if(url.indexof("?") > 0) { url = url.substring(0, url.indexof("?")); } url += "?joined=true"; window.location.replace(url);