2010-06-09 4 views
1

블로그를 통해 "ajax"라는 훌륭한 튜토리얼을 따라갔습니다 : http://www.deluxeblogtips.com/2010/05/how-to-ajaxify-wordpress-theme.html 그러나 문제는 아약스가 생성하는 해시에 있다고 생각합니다. . 콘텐츠가로드 된 후 어떻게 URL에서 해시를 제거 할 수 있습니까? 여기에 내 코드를 복사 :Ajax 로딩 후 해쉬 제거 (저는 AJAXING WordPress 8-입니다.)

jQuery(document).ready(function($) { 
    var $mainContent = $("#content"), 
     siteUrl = "http://" + top.location.host.toString(), 
     url = ''; 

    $(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/]):not([href*=/go.php]):not(.comment-reply-link)", "click", function() { 
     location.hash = this.pathname; 
$('html, body').animate({scrollTop:0}, 'fast'); 
     return false; 
    }); 

    $("#searchform").submit(function(e) { 
     location.hash = '?s=' + $("#search").val(); 
     e.preventDefault(); 
    }); 

    $(window).bind('hashchange', function(){ 
     url = window.location.hash.substring(1); 

     if (!url) { 
      return; 
     } 

     url = url + " #inside"; 

     $mainContent.html('<div id="loader">Caricamento in corso...</div>').load(url, function() { 
      //$mainContent.animate({opacity: "1"}); 
      scriptss(); 
     }); 
    }); 

    $(window).trigger('hashchange'); 
}); 

대단히 감사합니다!

+0

안녕하세요. 알베르토입니다. 답변이 도움이 될 경우 투표를 통해 '수락'으로 표시 할 수 있습니다. '답변'섹션은 '감사합니다'섹션에 적합하지 않습니다. – artlung

+0

감사합니다. 알베르토! StackOverflow를 즐기시 길 바랍니다! – artlung

답변

2

해시를 제거 하시겠습니까? 그냥 빈 문자열로 설정하십시오.

window.location.hash = ''; 

이것은 당신의 hashchange 이벤트를 설정합니다,하지만 당신은 확인하고 단지 해시가 비어있는 경우 반환 것 같습니다.

+0

도 확인할 수 있습니다. http://stackoverflow.com/questions/2295845/remove-hash-without-page-jump/2295896#2295896 –