2011-01-28 71 views
0

嘿,我不確定它是否可以完成,但我只是好奇。hashchange with attr('id')但使用jquery加載來自attr('href')的內容

這是我的代碼,我想知道,如果它在理論上可以工作...

//------------------------------------------------------------------ 
// Menu links 
//------------------------------------------------------------------ 
var newHash  = "", 
uri = "", 
$content = $("#main-content"), 
content = '#main-content', 
$wrap = $("#wrap"), 
baseHeight = 0, 
$el; 

$wrap.height($wrap.height()); 
baseHeight = $wrap.height() - $content.height(); 

$("nav a").live('click', function(){ 
    window.location.hash = $(this).attr("id"); 
    url = $(this).attr("href"); 
    uri = windows.location.hash; 
    return false; 
}); 
/*$("nav").delegate("a", "click", function() { 
    window.location.hash = $(this).attr("href"); 
    console.log(window.location.hash); 
    return false; 
});*/ 

$(window).bind('hashchange', function(){ 
    //window.location.hash = $(this).attr("href"); 
    //newHash = window.location.hash.substring(1); 
    u = uri.substring(1); 
    console.log(u); 
    if (window.location.hash = u) { 
     $wrap.find("#main-content").fadeOut(200, function() { 
      $wrap.load(u + " #main-content", function() { 
       $content.fadeIn(function() { 
        $wrap.animate({ 
         height: baseHeight + $content.height() + "px" 
        }, 500); 
       }); 
      }); 
     }); 
    } 
}); 
$(window).trigger('hashchange'); 

當前的行爲:
- 當我加載www.abc.com/的URI變成www.abc .COM /#自動
- !當我點擊菜單上的鏈接它把URI來www.abc.com/#!/files/2
(其中是用戶和的ID /文件/ 2是鏈接的ID)
- 點擊快速調用後,將URI轉換爲www.abc.com/file.php# ,它現在將直接從服務器直接加載文件,而不會從頁面加載內容的Ajax效果,而不是直接鏈接。

我已經在一個點上得到了成功的鏈接顯示爲:從file.php但這種成功

http://www.abc.com/#!/file/2和加載內容我無法在瀏覽器誘騙看到URI,它是什麼並加載內容從file.php基於頁面刷新的URI(用於書籤的原因)

回答

0

據我所知觸發器在瀏覽器中的URL(除了hashchanges)的變化加載新頁面(在這種情況下重新加載)。因此,在調用#!/ file/2時,不應在狀態欄中顯示「file.php」...