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); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -