2012-10-03 35 views
0

我正在使用一个图库查看器,并使用History.js来获取一个不错的链接。 这里是流量:History.js无法恢复为空状态

http://foo.com/gallery/show/显示主展厅

http://foo.com/gallery/show/photo1显示了照片

所以我用History.pushState观众({},“照片1”),以显示/去显示/照片1

我的问题是当我关闭查看器我想要的网址回来显示/所以我试过: History.pushState({},“”),但这并不工作,它只是停留在显示/照片1。

通过我真的不希望使用History.go(-X)已似乎不符合逻辑的我该用例的方式。

我该怎么做? 谢谢

+0

任何代码? jsfiddle? –

+0

它会是这样的:[链接](http://jsfiddle.net/rAxAw/) (我没有检查过,我的代码中的所有内容都是正确的,但是历史概念在那里)。 当你点击图片链接它应该显示的浏览器,当我点击的紧密联系我想要的地址回去/ – charly

回答

1

HTML:

<html> 
<head> 
</head> 
<body> 
    <a class='img' href="img1">Image 1</a> 
    <a class='img' href="img2">Image 2</a> 
    <div class="image-viewer" style="display:none"><p></p> 
    <a class="close" href="">Close</a> 
    </div> 
</body> 
</html> 
​ 

JS:

$(function() { 
var begin=location.href; 
$(".img").on('click', function(e) { 
    console.log(location.href); 
    var href = $(this).attr("href") 
    History.pushState({"state": href, "rand": Math.random()}, "", href); 
     console.log(location.href); 
    e.preventDefault(); 
}); 

History.Adapter.bind(window, 'statechange', function() { 
    $(".image-viewer p").html(History.getState()); 
    $(".image-viewer").show(); 
}); 

$(".close").click(function(e) { 
    e.preventDefault(); 
    console.log($(this).parent()); 
    $(this).parent().fadeOut(1); 
    History.pushState({"state": begin, "rand": Math.random()}, "", begin); 
}); 
​}) 

http://jsfiddle.net/rAxAw/2/

随意问任何Q-ñ如果需要futher帮助

+0

这是完美的更新地址/ IMAGEX。我奇怪地认为推动完整路径会使页面刷新。无论如何,它完美地工作,谢谢。 – charly