history.pushState does not trigger 'popstate' event

前端 未结 7 629
旧巷少年郎
旧巷少年郎 2020-12-16 12:13

Why

$(function () {
  $(window).bind(\'popstate\', function () {alert(\'pop\');});

  window.history.pushState(null, \'\', \'/foo\');
});

7条回答
  •  不知归路
    2020-12-16 12:31

    The paragraph you reference is a little ambiguous. Reading the example on the same page, it is clear that popstate is only triggered when the user clicks the back button, not when the script calls pushState().

提交回复
热议问题