history.pushState does not trigger 'popstate' event

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

Why

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

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

7条回答
  •  伪装坚强ぢ
    2020-12-16 12:21

    I ran into this too... I think the event only fires if you have something at the top level of your data object that is distinct from the previous state.

    Try this:

    var data = {rand: Math.random()};
    window.history.pushState(data, '', '/foo');
    

提交回复
热议问题