我正在使用一个网站,其中所有内容都是使用jquery通过ajax回发呈现的.我正在使用Ben Alman的hashchange(http://benalman.com/projects/jquery-hashchange-plugin/)来管理哈希历史记录,它允许我为页面添加书签,使用后退按钮等等...一切都可以完美地应用于所有内容IE 9当然.在IE中存在一个小问题,"访问"链接未标记为已访问.在加载新内容之前单击链接后,您可以看到该链接在一瞬间变为紫色(已访问).但是,一旦单击后退按钮,链接就会显示为从未访问过.以下是我所谈论的一个例子:http: //jsfiddle.net/7nj3x/3/
这里是jsfiddle代码,假设你有jquery和head中引用的hashchange插件:
$(function(){
// Bind an event to window.onhashchange that, when the hash changes, gets the
// hash and adds the class "selected" to any matching nav link.
$(window).hashchange( function(){
alert("Hash changed to:"+location.hash);
var hash = location.hash;
// Set the page title based on the hash.
document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
//simulate body being rendered by ajax callback
if(hash == ""){ …Run Code Online (Sandbox Code Playgroud)