54
rated 0 times
[
57]
[
3]
/ answers: 1 / hits: 15601
/ 7 Years ago, thu, december 21, 2017, 12:00:00
I have a single page app with pagination and filters, and need to detect when the current URL changes at all. Is there not a simple way to add a listener to the current URL and trigger something when it changes? (No setting intervals either!)
- User lands on www.foobar.com
- User does something, url changes to www.foobar.com?filter=hello
- My function runs
I have tried both onhashchange, and tried unbeforeunload, and neither are relevant for this.
window.onbeforeunload = function(e) {
alert ('url changed!');
};
window.onhashchange = function() {
alert ('url changed!');
}
Is there a way to add a listener to the URL, and trigger something anytime it changes at all? (again, single page app so no refresh)
More From » jquery