Multiple onpopstate event

3.2k views Asked by At

I need to work with History API for an application. My problem is that some "home" jQuery plugins already implement an event for popstate

it is possible to have more than one popstate event for an unique view ?

2

There are 2 answers

3
Axnyff On BEST ANSWER
window.addEventListener("popstate", console.log);
window.addEventListener("popstate", function(){console.log("I am also called")});

This seems to work fine for me.

Edit: Now with multiple events. For some reason Chrome won't fire twice the console log of the event though

0
st_phan On

I mistakenly used the following in two React components (Result: The second component overrides the behaviour of the first component, so it didn't trigger):

window.onpopstate = function (e) { /* Do something */ }

Instead I used the following:

window.addEventListener("popstate", /* Do something */ )