2012-10-03 57 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