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
Enter this in the console
window.onpopstate = function() {alert(1);}; history.pushState({}, '');
then click the back button.
I prefer to add a popstate listener as follows to prevent overwriting what is already in window.onpopstate:
window.onpopstate
window.addEventListener('popstate', function(){alert(1);});