2012-02-07 13 views
0

可能性の重複:
Making Browser Back button work while using AJAX requestsブラウザのバックボタン/ #one #twoなど

私はいくつかのjQueryを書きたいブラウザのURLの変更は(更新されていない)、それがどうなるときアクション。

私はURLはそう、彼らは

  • www.hello.com/#one
  • www.hello.com/#two www.helloになりますがどうなるか、100%を知っているだろう。 co.jp /#three

私はアクションについて心配していません(私はそれを分類できます)。リフレッシュされていないときにURLが変更されたことを検出する方法があります。

任意のポインタ?

プラグインを使用したくないのは、私が達成しようとしていることの詳細を知っているように、私は自分が必要としているものが過度であると感じているからです。

+0

ありがとうございました。読んでいただきありがとうございます – odd

答えて

1

私のプロジェクトの1(http://yankele.co.il

$(document).ready(function() { 

    //Declare some variables... 
    var $mainContent = $('.main-content'), 
     contentHeight = $mainContent.height(), 
     siteURL = 'http://' + top.location.host.toString(), 
     hash = window.location.hash, 
     $internalLinks = $('a[href^=' + siteURL + ']'), 
     $ajaxSpinner = $('#spinner'), 
     URL = '', 
     $el; 
     console.log(contentHeight); 

    $mainContent.height(contentHeight);  
    $internalLinks.each(function() { 

     $el = $(this); 
     $el.attr('href', '#' + this.pathname); 

    }).click(function() { 

     $ajaxSpinner.fadeIn(); 
     $mainContent.animate({opacity: '0.1'}); 
     $('.current_page_item').removeClass('current_page_item'); 
     $el = $(this); 
     URL = $el.attr('href').substring(1); 
     URL += ' #inside'; 
     $mainContent.load(URL, function() { 
     marquee(); 
     $ajaxSpinner.fadeOut(); 
     $mainContent.animate({opacity: '1'}); 
     $el.parent().addClass('current_page_item'); 
     contentHeight = parseInt($mainContent.css('paddingTop')) + parseInt($mainContent.css('paddingBottom')) + $('#inside').height(); 
     $mainContent.animate({height: contentHeight}); 
     }); 

    }); 

    if (hash != '' && hash != '#/') { 

     $ajaxSpinner.fadeIn(); 
     $mainContent.animate({opacity: '0.1'}); 
     $('.current_page_item').removeClass('current_page_item'); 
     URL = hash.substring(1); 
     URL += ' #inside'; 
     $('a[href="'+window.location.hash+'"]').addClass('current_link').parent().addClass('current_page_item'); 
     $mainContent.load(URL, function() { 
     marquee(); 
     $ajaxSpinner.fadeOut(); 
     $mainContent.animate({opacity: '1'}); 
     contentHeight = parseInt($mainContent.css('paddingTop')) + parseInt($mainContent.css('paddingBottom')) + $('#inside').height(); 
     $mainContent.animate({height: contentHeight});   
     }); 

    } 

}); 

から取った次のコードをチェックアウトそれは古いですが、それは動作しますが、メインのコンテンツ領域内の任意のリンクをクリックしたときにどのようなそれがないこと、である、メインコンテンツが白くなると、AJAXスピナーが表示され、ページにAJAXのリンクが読み込まれます。リフレッシュ時にも機能します。

+0

私はその歓声で作業できるかもしれません – odd

関連する問題