You could simply have just done:
var varAppend = "?single";
window.location.href = window.location.href.replace(".com",".com" + varAppend);
Unlike the other answers provided, there is no needless conditional check. If you design your project properly, you'll let the interface make the decision making and calling that statement whenever an event has been triggered.
Since there will only be one ".com" in your url, it will just replace .com
with .com?single
. I just added varAppend
just in case you want to make it easier to modify the code in the future with different kinds of url variables.
One other note:
The .replace
works by adding to the href since href returns a string containing the full url address information.