2013-10-19 137 views
0

我有3個鏈接,2與pushstate數據1沒有。用戶+標籤鏈接有數據,主題不。如果我點擊用戶然後主題然後回來或標記然後主題然後回它完美。如果我點擊用戶然後標籤然後點擊它將只加載最後pushstate(標籤)。如果我點擊標籤,然後用戶回來它只是重用用戶pushstate。如果我去標籤 - >用戶 - >主題,返回將轉到用戶,回來也將是用戶??pushstate只能工作一次

$('#changetousers').click(function() { 
    $('#loadingAjaxs').show(); $('#flubestext').hide(); 
    $('#contentwrap').load('@Url.Action("FollowingUsersDetail", "Following", new {@ajax = "yes"})', function() { $('#loadingAjaxs').hide(); $('#flubestext').show(); window.history.pushState({ "page": "followingusers" }, 'title1', '/users/'); window.onpopstate = function (e) { document.getElementById('changetousers').click(); }; 
    }) 
}); 

$('#changetotags').click(function() { 
    $('#loadingAjaxs').show(); $('#flubestext').hide(); 
    $('#contentwrap').load('@Url.Action("FollowingTagsDetail", "Following", new {@ajax = "yes"})', function() { $('#loadingAjaxs').hide(); $('#flubestext').show(); window.history.pushState({ "page": "followingtags" }, 'title2', '/tags/'); window.onpopstate = function (e) { document.getElementById('changetotags').click(); }; }) 
}); 

$('#changetofavorites').click(function() { 
    $('#loadingAjaxs').show(); $('#flubestext').hide(); 
    $('#contentwrap').load('@Url.Action("FollowingTopicsDetail", "Following", new {@ajax = "yes"})', function() { $('#loadingAjaxs').hide(); $('#flubestext').show(); window.history.pushState(null, 'title', '/favorites/'); }) 
}); 

回答

1

我想你調用pushState即使用戶點擊退,這就是爲什麼你不能去以前的狀態。這應該工作:

function loadUserDetails() { 
    $('#loadingAjaxs').show(); 
    $('#flubestext').hide(); 
    $('#contentwrap').load(
     '@Url.Action("FollowingUsersDetail", "Following", new {@ajax = "yes"})', 
     function() { 
      $('#loadingAjaxs').hide(); 
      $('#flubestext').show(); 
     }); 
} 
$('#changetousers').click(function() { 
    loadUserDetails(); 
    window.history.pushState({ "page": "followingusers" }, 'title1', '/users/'); 
    window.onpopstate = function (e) { loadUserDetails(); }; 
});