I'm trying to set a URL on the browser back button. I've looked at a few examples and found this code and it works. The problem is when I click on an anchor button it does the same as when I click on the browser back button.. this is not good. I believe the problem is with this line of code - I could be wrong -
window.addEventListener('popstate', function(event){ ... })
Here's the code -
history.pushState(null, null, '<?php echo $_SERVER["REQUEST_URI"]; ?>');
window.addEventListener('popstate', function(event) {
window.location.assign("http://newurl.com");
});
I've been working on this all day and cannot find a solution. Can someone help?