Luca Reghellin
Luca Reghellin

Reputation: 8103

How to know when a url hash has been manuallly (writing) changed?

is there a way, or a tool (js plugin or other) that let me know when I manually change the hash part of the URL? Note: with 'manual' i mean, I'm here:

http://www.[mydomain].com/#hash1

and then I cancel and rewrite the hash with mouse/keaboard, OR, clicking back/next browser buttons.

http://www.[mydomain].com/#hash2

Upvotes: 0

Views: 34

Answers (1)

front_end_dev
front_end_dev

Reputation: 2056

window object has a hashchange event that is fired when url hash changes

window.addEventListener("hashchange", function(event){
 console.log('hash change event =>',event);
}, false);

Read more from mdn documentation - https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onhashchange

Upvotes: 1

Related Questions