2011-08-25 73 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浏览器的书签会按预期工作)