history.pushstate:history.back和back按钮的行为不同

时间:2018-07-18 14:17:58

标签: javascript browser browser-history pushstate

Mozilla documentation中可以看到

  

要回顾历史,只需执行以下操作:

     

window.history.back();

     

这与用户在   他们的浏览器工具栏。

尽管如此,当我使用window.history.pushState时,后退按钮的作用与window.history.back();不同。

当点击按钮时,我得到想要的结果;浏览器将我带回到最后的状态。但是当我使用window.history.back()函数时,它将带我回到上一个实际加载的页面。

是否需要使用其他功能或配置参数进行调整? 该错误在Firefox和Chrome中都发生

谢谢:)


一些代码:

var stateObj = {info: ""};

$(window).on("popstate", function () {
  // if the state is the page you expect, pull the name and load it.
  window.location.reload();
});

history.pushState(stateObj, "", preloadid);

0 个答案:

没有答案