检查浏览器后退按钮历史记录

Check Browser back button history

本文关键字:历史 记录 按钮 浏览器 检查      更新时间:2023-09-26

我有一个单页应用程序,在某些按钮/链接上调用了一些角度js函数,它改变了页面内容。现在,由于它是单页浏览器,因此将保存原始页面的历史记录,而不是被单击并更改内容的角度js链接。但是我想将该历史记录存储在最近访问的页面中,以便如果有人单击浏览器后退按钮,将加载以前的内容。

例如,

假设我访问了first Google home page them my app and then click on any link which changes the content of page .

谷歌主页(1)>我的应用程序(2)>点击链接和内容更改(3)。

原始行为将是单击浏览器后退按钮时 -> back button will load Google home page .

目前我在 (3) 页面上,后退按钮会将我发送到 (1) 页面而不是 (2)

预期行为 ->

click on browser back button must move me as 
  (3) then (2) then (1) goggle home page

您可以在路由器函数中使用 html 推送状态。例如:

var enablePushState = true
pushState = !!(enablePushState && window.history && window.history.pushState)
if (pushState) // New Browser supported
    Backbone.history.start({ pushState: true, root: "/" }); 
else // Old Browser supported
    Backbone.history.start();