I have implemented History.js
with History.pushState
fuction. Here is code below:
我用History.pushState函数实现了History.js。这是下面的代码:
function PushStateUrl(stateUrl) {
manualStateChange = false;
History.pushState({ loadUrl: stateUrl, rand: Math.random() }, document.title, stateUrl);
}
And on browser's back button, this code executes:
在浏览器的后退按钮上,此代码执行:
$(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;
});
});
But I want to use replaceState()
instead of pushState()
. Please guide me to what changes needs to use history.replaceState()
但我想使用replaceState()而不是pushState()。请指导我使用history.replaceState()需要进行哪些更改
1 个解决方案
#1
0
But I want to use replaceState() instead of pushState(). Please guide me to what changes needs to use history.replaceState()
但我想使用replaceState()而不是pushState()。请指导我使用history.replaceState()需要进行哪些更改
Change the word push
to replace
in your code. The two functions take the same arguments.
在代码中更改单词push以替换。这两个函数采用相同的参数。
Obviously, if you do that everywhere, then your code for handling the back button becomes redundant (because you are never going to be going back to a stored state).
显然,如果你到处都这样做,那么处理后退按钮的代码就变得多余(因为你永远不会回到存储状态)。
#1
0
But I want to use replaceState() instead of pushState(). Please guide me to what changes needs to use history.replaceState()
但我想使用replaceState()而不是pushState()。请指导我使用history.replaceState()需要进行哪些更改
Change the word push
to replace
in your code. The two functions take the same arguments.
在代码中更改单词push以替换。这两个函数采用相同的参数。
Obviously, if you do that everywhere, then your code for handling the back button becomes redundant (because you are never going to be going back to a stored state).
显然,如果你到处都这样做,那么处理后退按钮的代码就变得多余(因为你永远不会回到存储状态)。