The documentation for the popstate
Window event states:
Note that just calling
history.pushState()
orhistory.replaceState()
won't trigger apopstate
event. Thepopstate
event will be triggered by doing a browser action such as a click on the back or forward button (or callinghistory.back()
orhistory.forward()
in JavaScript).
I need a way to execute some code when the URL changes by means that don't trigger the popstate
event (such as history.replaceState()
). Preferably, using the MutationObserver API[1], and most definitely without polling the URL every x seconds.
Also, hashchange
won't do, as I must act on every change in the URL, not just the hash part.
Is that possible?
[1] It is explained on another question why the MutationObserver API doesn't work for this.
(other) Related questions:
- Is it possible to capture the window.location.replace event?
- Event when window.location.href changes
- Attaching change notifier for window.location
- How to detect URL change in JavaScript
- history.pushState does not trigger 'popstate' event
from How to observe a change in the URL using JavaScript?
No comments:
Post a Comment