【问题标题】:Is it possible to determine whether the current browser tab has history? [duplicate]是否可以确定当前浏览器选项卡是否有历史记录? [复制]
【发布时间】:2013-05-17 09:18:26
【问题描述】:

我在视图上有一个按钮,提交时使用window.history.go(-1); 将用户的浏览器引导回上一页。这对于我们维护会话数据以正确显示之前的视图是必要的。

我的问题是,我们是否可以使用 jQuery 确定是否有任何浏览器历史记录,如果没有,我们可以使用

重定向用户
window.location = "/Transaction/Index";

到正确的页面?

提前致谢!

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    来自MDN

    HTML5 引入了history.pushState()history.replaceState() 方法,允许您添加和修改历史条目, 分别。这些方法与 window.onpopstate 事件。

    使用history.pushState() 会更改在 更改后创建的 XMLHttpRequest 对象的 HTTP 标头 状态。引用者将是其窗口所在的文档的 URL this 在创建 XMLHttpRequest 对象时。

    例子:

    var stateObj = { foo: "bar" };
    history.pushState(stateObj, "page 2", "bar.html");
    

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 2017-11-04
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      相关资源
      最近更新 更多