我想用browswerback按鈕獲取wordpress ajax文章,意思是當用戶點擊瀏覽器後退按鈕時,然後發佈前點擊標題的帖子將顯示,我想使用瀏覽器後退按鈕顯示以前的帖子,對於這個我已經使用這個代碼,它是工作正常,當用戶點擊帖子,但它不是與瀏覽器後退按鈕,我堅持這個問題。 任何人都可以告訴我這個問題的解決方案。如何更改onhashchange值點擊wordpress中的瀏覽器後退按鈕ajax
success: function(response) {
jQuery("#loading-animation").addClass('loadingstyle');
jQuery("#loading-animation").text(function(){
if(location.hash){
// We got a hash value! Lets take off the hash and smoke it.
var newhash = window.location.hash.substring(1);
jQuery("#loading-animation").html(response);
// uncomment the above code to see if it works.
}else{
alert("No hash available.");
// no hash value
}
$(".ajaxclick").click(function(e){
e.preventDefault();
window.location.hash = $(this).attr("href");
});
// $(window).on('hashchange', function() {
window.onhashchange = function(){
// hash changed. Do something cool.
if(location.hash){
var hash = window.location.hash.substring(1);
// console.log(response);
jQuery("#loading-animation").html(response);
}else{
// load home page
// jQuery("#loading-animation").html(response);
alert("No more content to show");
}
}
});
return false;
}
我已刪除,但它仍然無法正常工作。它只是加載了職位,但不顯示以前的帖子用瀏覽器按鈕 – ravinder
window.onhashchange =函數(){ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t //散列改變。做一些很酷的事。 \t \t \t \t \t \t \t \t \t如果(的location.hash){ \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t變種散列= window.location.hash.substring( 1); \t \t \t \t \t \t \t \t \t \t //的console.log(響應); \t \t \t \t \t \t \t \t \t \t // jQuery的( 「#加載動畫」)。HTML(響應); \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t}其他{ \t \t \t \t \t \t \t \t \t \t //負荷主頁 \t \t \t \t \t \t \t \t \t \t // jQuery(「#loading-animation」)。html(response); \t \t \t \t \t \t \t \t \t \t警報( 「沒有更多的內容,以示」); \t \t \t \t \t \t \t \t \t} \t \t \t \t \t \t \t} – ravinder
此功能無法正常工作,這部分只有其他部分工作,當我按下後退按鈕它顯示警報消息僅 – ravinder