如何使用replaceState()而不是pushState()

问题描述 投票:0回答:1

我用qazxsw poi函数实现了qazxsw poi。这是下面的代码:

History.js

在浏览器的后退按钮上,此代码执行:

History.pushState

但我想使用function PushStateUrl(stateUrl) { manualStateChange = false; History.pushState({ loadUrl: stateUrl, rand: Math.random() }, document.title, stateUrl); } 而不是$(function () { History.Adapter.bind(window, "statechange", function () { var State = History.getState(); var url = ((State.data.loadUrl == "undefined") ? State.data.loadUrl : State.url); if (typeof (manualStateChange) !== "undefined" && manualStateChange == true) { AjaxCall(url); } else if (typeof (State.data.loadUrl) == "undefined") { AjaxCall(url); } manualStateChange = true; }); }); 。请指导我使用replaceState()需要哪些更改

javascript jquery ajax history.js
1个回答
0
投票

但我想使用replaceState()而不是pushState()。请指导我使用history.replaceState()需要进行哪些更改

在代码中将单词pushState()更改为history.replaceState()。这两个函数采用相同的参数。

显然,如果你到处都这样做,那么处理后退按钮的代码就变得多余(因为你永远不会回到存储状态)。

© www.soinside.com 2019 - 2024. All rights reserved.