karkael
karkael

Reputation: 473

Event "onpopstate" VS "onhashchange"

I would like my script triggers a function when the hash changes or when the user navige in its history. When I associate the two events to the same function, the events onpopstate and onhashchange fire both when the hash changes, making a double call of my function.

Which is better to keep? onpopstate or onhashchange?

Upvotes: 9

Views: 1921

Answers (1)

Vikas Dubey
Vikas Dubey

Reputation: 340

if we talk about chrome browser- when you will change url both events will get fired. But if you will try the same with lets say IE11, only event which will get fired is onhashchange not onpopstate. I had the same issue and at last i decided to keep only onhashchange which is working fine in both the browsers.

Upvotes: 3

Related Questions