Basically you can use this:
window.history.go(-(history.length - 1));
window.location.replace('your new url');
the trick is on the first line you go back to the first page in the history, then location.replace() makes sure that one is forgotten as well. Or you can use other navigation means after the first line, as you wish.