Mandatory popstate event not working

I tried to enter this code into the browser console:

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

and then click the back button. A warning is not displayed. Am I doing something wrong? Or is it not allowed to bind a popstate event to a page from the console?

Using Chrome 24 and Firefox 18

+5
source share
2 answers

Enter this in the console

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

then click the back button.

+10
source

I prefer to add a popstate listener as follows to prevent overwriting what is already in window.onpopstate:

window.addEventListener('popstate', function(){alert(1);});
+3
source

All Articles