2011-08-25 75 views
6

jQuery插件HISTORY.js(https://github.com/browserstate/History.js/)提供HTML5歷史記錄推送實現功能,並且在不支持瀏覽器的情況下,應該能夠實現HTML4主題標籤功能。文檔/ README文件詳細介紹了使用像這樣:Implementing History.js HTML4 Fallback

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; 
    } 

正如你可以看到,文件解釋了HISTORY.js插件到HTML5的點使用,不解釋HTML4支持的使用。

然而,文檔中的「下載&安裝」部分下,它讀取:

5. Include History.js 
<script src="http://www.yourwebsite.com/history.js/scripts/compressed/history.js">/script> 
<script src="http://www.yourwebsite.com/history.js/scripts/compressed/history.html4.js"></script> 

在這裏指令可以傳達的HTML4包括hashtag是自動支持的,但使用頁面上的說明表明,它必須手動實施;我認爲這實際上就是這種情況。

我找不到任何關於實現HTML4哈希標籤功能的進一步文檔。請幫我弄清楚這一點。

+0

你有這樣的表述方式,它很可能被關閉。請解釋您嘗試的內容,並提供有關哪些工作不正常以及需要幫助的地方的明確示例。否則,請閱讀該工具的文檔,並尋找一個論壇來進行更一般的討論。 [請參閱「我不應該在這裏問什麼樣的問題?」](http://stackoverflow.com/faq#dontask) – OverZealous

+0

好的,對不起。謝謝你告訴我我做錯了什麼。我只是認爲,如果我寫了太多的人不會讀它。我將編輯帖子以進一步解釋。 –

+0

你試過了嗎?這聽起來像插件會自動降級(它可以與HTML4一起工作,不需要額外的實現)。 – JJJ

回答

1

好吧,也許問題是你沒有以正確的方式使用History.js(這也是我所遇到的問題)。基本上使用History.js你必須做這樣的事情的正確方法:

// Register navigation click handlers where you will load Ajax content 
$(window).on('click', 'a.ai1ec-load-view', handle_click_on_link_to_load_view); 
// Bind to the statechange event 
$(window).bind('statechange', handle_state_change); 

// When the state changes, load the corresponding view 
var handle_state_change = function(e) { 
    var state = History.getState(); 
    load_view(state.url, 'json'); 
}; 

// When clicking on a link you want to load, trigger statechange by changing state 
var handle_click_on_link_to_load_view = function(e) { 
    e.preventDefault(); 
    History.pushState({ target :this }, null, $(this).attr('href')); 
}; 

這樣做我不聽statechange之前和我只是在鏈接的點擊處理程序使用pushState的()。

如果你像這樣做沒有必要編寫一個後備,它也將工作在HTML4瀏覽器(從HTML4瀏覽器的書籤會按預期工作)