历史.js无法回到空状态



我正在开发一个图库查看器,我使用历史记录.js来获得一个很好的链接。以下是流程:

http://foo.com/gallery/show/显示主图库

http://foo.com/gallery/show/photo1 向观看者显示照片

所以我使用 History.pushState({}, "photo1") 从 show/转到 show/photo1

我的问题是当我关闭查看器时,我希望网址回来显示/所以我尝试了:History.pushState({}, ") 但这不起作用,它只是停留在 show/photo1。

顺便说一句,我真的不想使用 History.go(-X),在那个用例中对我来说似乎不合逻辑。

我该怎么做?谢谢

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/

如果需要进一步的帮助,请随时询问任何问题

最新更新