2012-11-06 45 views
0

可能你認爲這是重複的,但這是不重複的。更改URL與jQuery的像Facebook消息

change-hash-without-reload-in-jquery這個主題 更改URL中的字符#後,但如果你看看Facebook的消息URL變化,你可以看到,Facebook的變更網址沒有任何額外#字符。

facebook.com/message/user1 

,如果你點擊第二用戶信息將被改變,如:

facebook.com/message/user2 

此網址更改,恕不重定向和使用#字符。

+2

這是最可能的服務器端URL重寫。 – pmandell

+2

它被稱爲[HTML5歷史API](http://diveintohtml5.info/history.html),這是一堆類似問題的重複。 – adeneo

回答

2

History.js是您通過跨瀏覽器支持完成此操作的最佳選擇。您應該認識到,舊版瀏覽器不支持直接處理URL,並且使用散列標籤(#)機制。

這裏是他們的入門款的部分:直接使用HTML5 pustState

(function(window,undefined){ 

    // Prepare 
    var History = window.History; // Note: We are using a capital H instead of a lower h 
    if (!History.enabled) { 
     // History.js is disabled for this browser. 
     // This is because we can optionally choose to support HTML4 browsers or not. 
     return false; 
    } 

    // Bind to StateChange Event 
    History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate 
     var State = History.getState(); // Note: We are using History.getState() instead of event.state 
     History.log(State.data, State.title, State.url); 
    }); 

    // Change our States 
    History.pushState({state:1}, "State 1", "?state=1"); // logs {state:1}, "State 1", "?state=1" 
    History.pushState({state:2}, "State 2", "?state=2"); // logs {state:2}, "State 2", "?state=2" 
    History.replaceState({state:3}, "State 3", "?state=3"); // logs {state:3}, "State 3", "?state=3" 
    History.pushState(null, null, "?state=4"); // logs {}, '', "?state=4" 
    History.back(); // logs {state:3}, "State 3", "?state=3" 
    History.back(); // logs {state:1}, "State 1", "?state=1" 
    History.back(); // logs {}, "Home Page", "?" 
    History.go(2); // logs {state:3}, "State 3", "?state=3" 

})(window); 

查閱這些例子:一個類似的

問題話題:

其他資源:

+0

@irplayboy這是你在找什麼? –

+0

感謝布蘭登。是的 – OceanOne