How would I know when the path or URL
changes it using javascript
? For example, some event that is fired when the current url is changed.
//Por ejemplo algún listener que permita ejecutar una función al detectar algún cambio.
document.addEventListener('algunevento', function(){}, false);
Any ideas?
The event is called
onhaschange
:It should be noted that you have to check if the browser supports it:
If you are talking about the url that appears in the browser, that url is in the window.location.href variable, from there you have a series of events to control that someone leaves the page, if that is what you want to know, no It's clear to me what the goal is.
Take a look here to see if this is what you're looking for: