2013-04-18 54 views
0

我想用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; 
    } 

回答

0

您正在使用e.preventDefault();,導致停止進一步的事件(點擊)。

因此,從下面的代碼

$(".ajaxclick").click(function(e){ 
     e.preventDefault(); 
    window.location.hash = $(this).attr("href"); 
}); 
+0

我已刪除,但它仍然無法正常工作。它只是加載了職位,但不顯示以前的帖子用瀏覽器按鈕 – ravinder

+0

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

+0

此功能無法正常工作,這部分只有其他部分工作,當我按下後退按鈕它顯示警報消息僅 – ravinder

0

您可以用下面的代碼替換onchange功能刪除e.preventDefault();

window.onhashchange = function(){ 
    if(location.hash){ 
      var hash = $('.ajaxclick').attr('href'); 
      jQuery("#loading-animation").html(response); 

    }else{ 
     alert("No more content to show"); 
    } 
}  
+0

嗨Ravidra你可以嘗試這一個 – VenkateshKumar

+0

謝謝我已經嘗試過,但它不工作:( – ravinder

+0

我已經使用此代碼爲hashchange,它顯示警報時,當我使用後退按鈕和前進按鈕,但我因爲它顯示哈希值,但不知道如何將哈希值與ajax後綴綁定在一起,所以我堅持認爲如何使用backbutton來更改ajax發佈內容。 「).addClass('loadingstyle'); \t jQuery(」#loading-animation「)。html(response,$(function(){ $(window).bind('hashchange',function(){ \t var hash = window.location.hash; \t alert(散列); }); }) ); 返回false; \t} – ravinder

相關問題