What about using [onhashchange](https://developer.mozilla.org/en-US/docs/Web/API/Window.onhashchange) instead?