When the browser forward or back button is pushed, I use the code below to detect a URL parameter change. Note, the page never really changes, only the parameter that I add using a HTML data attribute.
window.navigation.addEventListener("navigate", (event) => {
var changedURL = event.destination.url;
console.log(changedURL);
In the console log, I get the below.
practice.php?url=homepage:58 http://localhost/practice.php?url=page3
I want to get only the very end of the result, i.e., “?=page3”. I want to save that parameter only in a variable, and nothing before it.