binding popstate event not working

mirelon picture mirelon · Feb 7, 2013 · Viewed 16.4k times · Source

I have tried to type this code into the browser's console:

window.onpopstate = function() {alert(1);}

and then click the back button. No alert has shown. Am I doing something wrong? Or is it not allowed to bind popstate event to a page from console?

Using Chrome 24 and Firefox 18

Answer

Sean Hogan picture Sean Hogan · Feb 8, 2013

Type this into the console

window.onpopstate = function() {alert(1);}; history.pushState({}, '');

then click the back button.