2011-08-17 60 views
1

我在我正在開發的網站上有一個選項卡式部分,並且希望爲每個選項卡啓用唯一的URL以及歷史記錄支持。jQuery地址/深層鏈接問題

看來jQuery地址插件是要走的路,但我在實施時遇到了麻煩。我可以分配網址並更改地址欄。後退按鈕遍歷URL,但實際上並沒有改變標籤。

地址文檔不是很好。我假設我錯過某種事件監聽器,但我不知道如何初始化它或應用它。

這裏是我的JS

$('.sm-tab').click(function() { 
    $.address.value($('a', this).attr('href')); 
    smReset(); 
    $('#sm-tabs').find('.active').each(function() { 
     $(this).removeClass('active'); 
     $(this).addClass('inactive'); 
    }); 
    $(this).removeClass('inactive'); 
    $(this).addClass('active'); 
    var smClassArray = $(this).attr('class').split(" "); 
    var smDivClass = smClassArray[1]; 
    $('#'+smDivClass).show(); 
}); 

我的HTML看起來像這樣

<div id="sm-tabs"> 
    <div class="sm-tab inactive twitter"> 
     <span class="twitter sprite-sm-twitter"><a href="?tab=twitter" class="hidetext">Twitter</a></span> 
    </div> 
    <div class="sm-tab inactive youtube"> 
     <span class="youtube sprite-sm-youtube"><a href="?tab=youtube" class="hidetext">YouTube</a></span> 
    </div> 
</div> 

<div id="sm-widgets"> 
    <div id="twitter"> 
     Content 
    </div> 
    <div id="youtube"> 
     Content 
    </div> 
</div> 
+0

請參閱:http://stackoverflow.com/questions/172957/detecting-back-button-hash-change-in-url –

回答

1

使用Ajax的導航哈希值是要打開你a whole can of worms

嘗試使用HTML5 History API代替this deep-linking script

+0

我實際上需要避免完全使用哈希。我有一個YouTube身份驗證重定向,當它返回到我的頁面時,它會覆蓋並散列。我希望我可以讓地址工作沒有哈希,但看起來這可能是不可能的? – Derek

+0

當然,使用上面提到的深層鏈接腳本,但不包括'history.html4.js'這是HTML4支持(也就是哈希的東西)。 – balupton