Sam
Sam

Reputation: 4339

PopState not firing after coming back from another site

My popstate event handler is defined thusly:

window.addEventListener('popstate', function (ev) { 
    alert('popstate');
    /* recompose dom */
});

It works fine while I am within my site as I use back and forward, however when I navigate to another site and then come back my event does not fire.

I assume this is by design based on the following comment on Mozilla Developer:

Browsers tend to handle the popstate event differently on page load. Chrome (prior to v34) and Safari (prior to 10.0) always emit a popstate event on page load, but Firefox doesn't.

If this is the case, how do I get the most recent pushed state when coming back to my page from another site.

Upvotes: 1

Views: 1046

Answers (1)

Sam
Sam

Reputation: 4339

I figured it out; pull the current page state from history.state on document ready and apply it.

Upvotes: 2

Related Questions