2011-11-25 191 views
1

我正在使用此JavaScript代碼來動畫和加載我的網站!更改頁面時,使JS更改URL(使用hashtag)

$('.down-trigger').on('click', function() { 
var toLoad = $(this).attr('href')+' #container'; 
    $('#container').attr('id','to-go'); 
    $('#wrapper').append('<div id="newcontainer"/>'); 
    $('#newcontainer').load(toLoad, function() { 
     $('#newcontainer').append($('#container').children()).css({'position': 'absolute', 'top': '696px'}); 
     $('#to-go, #newcontainer').animate({top:'-=691'},600, function() { 
     $('#to-go').remove(); 
     var lastchild = $('.page:last-child'); // ignore these lines 
     var found = lastchild.find('div.slide'); // this one 
     if (found.length == 0) { lastchild.remove(); } // and this one 
     carousels(); // and this one too 
     }); 
    $('#container').remove(); 
    $('#newcontainer').attr('id','container'); 
    searchform(); // these two lines can be ignored too 
    triggers(); // this is the second line to ignore 
    }); 
    return false; 
});` 

你們可以幫助用戶點擊鏈接時更改網址嗎?

我知道我必須使用像window.location.hash,但我真的不知道從哪裏開始。

謝謝。

回答

1
window.location.href = 'myNewUrl.html'; 
+0

我應該在哪裏放置它? – Mysteriis

+0

有點難以分辨代碼究竟發生了什麼......你最好判斷,但是你把代碼放在你的代碼中的任何地方,你都準備好轉換到下一頁。 –

+0

完成!謝謝傑克 – Mysteriis