Question: I'm having a problem with a 'popstate' event handler, this is my code:

```
window.addEventListener("popstate", function (event){
    if (event.state) {
        alert('abc')
    }
});

// The data object is arbitrary and is passed with the popstate event.
var dataObject = {
    createdAt: '2011-10-10',
    author: 'donnamoss'
};

var url = '/posts/new-url';
history.pushState(dataObject, document.title, url);

```

I expected this code will pop up an alert box when it's executed but, nothing happens. 

Is there anything wrong here?

Thank you.

Answer: 
No it will not,

As per [MDN documentation](https://developer.mozilla.org/en-US/docs/Mozilla_event_reference/popstate)

> 
> Note that just calling history.pushState() or history.replaceState() won't trigger a popstate event. The popstate event is only triggered by doing a browser action such as a click on the back button (or calling history.back() in JavaScript).
> 
> 
> 

Again as per [this question](https://stackoverflow.com/questions/8195502/chrome-onpopstate-pushstate-bug) the `popstate` event is not triggered in `Chrome` when you call `pushState()`.
[`history.pushState()`](https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history#The_pushState%28%29.C2.A0method) will not trigger the [`popstate`](http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-popstate) event by definition.

> 
> The popstate event is fired in certain cases when navigating to a session history entry.
> 
> 
> 

This event is intended to be only triggered when navigating to a history entry, either by pressing the back/forward button, or `history.go/back`.