Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取哈希更改后的最后一个哈希_Javascript_Backbone.js_Browser History - Fatal编程技术网

Javascript 获取哈希更改后的最后一个哈希

Javascript 获取哈希更改后的最后一个哈希,javascript,backbone.js,browser-history,Javascript,Backbone.js,Browser History,我有一个主干应用程序,我想在其中打开一个覆盖,它只是一个带有其on url的页面。您还可以使用不同的页面/URL在此覆盖中导航。所以当覆盖被关闭时,我想把散列设置回覆盖被打开之前的状态。由于覆盖是由链接打开的,我无法从以前的状态获取哈希 那么,有没有一种方法可以在哈希更改时获取上一个哈希?哈希更改事件有一个“oldURL”字段。。。。存储所有“oldURL”(或仅最后一个),并在需要时使用最后一个url更改实际url 来源:我想出了这个小技巧。当覆盖层打开时,我存储窗口.history.leng

我有一个主干应用程序,我想在其中打开一个覆盖,它只是一个带有其on url的页面。您还可以使用不同的页面/URL在此覆盖中导航。所以当覆盖被关闭时,我想把散列设置回覆盖被打开之前的状态。由于覆盖是由链接打开的,我无法从以前的状态获取哈希


那么,有没有一种方法可以在哈希更改时获取上一个哈希?

哈希更改事件有一个“oldURL”字段。。。。存储所有“oldURL”(或仅最后一个),并在需要时使用最后一个url更改实际url


来源:

我想出了这个小技巧。当覆盖层打开时,我存储
窗口.history.length
。当覆盖层关闭时,我调用
window.history.go
,将存储的长度与实际长度之差减去1

var appStateActions = {
  overlayPre: function(){
    this.historyPosition = window.history.length;
  },
  overlayExit: function(){
    window.history.go(this.historyPosition - window.history.length -1);
  }
}

不幸的是,由于历史的限制,这一点行不通。因此,当您达到历史长度的限制时,您会得到一个错误的结果。

保存
oldUrl
,并通过
窗口返回到旧位置。location.replace(oldUrl)
是一种方法。谢谢
var historyurl =[];

$(window).on('hashchange', function(e){
    historyurl.push(location.hash); 
   if(historyurl.length > 2){ 
       historyurl.splice(0,historyurl.length-2)
     }; 
});

console.log("Last Hah Url ="+historyurl[0])