Popstate - passing popped state to event handler
问题 The following code should cause an alert of '1', but instead does nothing. window.onpopstate = function(event) { alert(event.state.a) } history.pushState({a: 1}) history.back() Fiddle: http://jsfiddle.net/WNurW/2/ Any ideas? 回答1: Your code woudn't cause a popstate, as the pushstate command tells what page you are on NOW. window.onpopstate = function(event) { alert(event.state.a) } history.pushState({a: 1}); history.pushState({a: 2}); history.back() The above code will work. Heres the fiddle: