jQuery plugin HISTORY.js (https://github.com/browserstate/History.js/)提供了HTML5历史推送实现功能,在不支持浏览器的情况下,应该能够实现HTML4标签功能。文档/自述文件详细说明了用法:
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;
}正如您所看到的,文档从HTML5的角度解释了HISTORY.js插件的用法,但没有解释HTML4支持的用法。
但是,在文档的"Download & Installation“部分,它显示:
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标签支持是自动的,但用法页面上的说明表明它必须手动实现;我相信事实确实如此。
我找不到任何关于实现HTML4标签特性的文档。请帮我弄清楚这件事。
发布于 2012-09-27 22:45:39
好吧,也许问题是你没有以正确的方式使用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浏览器的书签也会按预期工作)
https://stackoverflow.com/questions/7186466
复制相似问题