Re: [問題] url hash上一頁鍵的問題

看板Ajax作者 (拒絕崩潰的蒲公英)時間12年前 (2012/12/19 11:06), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《sean123362 (早知如此..)》之銘言: : 目前是在寫類似翻書功能的網頁 : 也就是照著hash的順序翻頁下去 : 例如我現在有四個頁面 : xxx.com/index.html : xxx.com/abc.html#1 : xxx.com/abc.html#2 : xxx.com/abc.html#3 : 我先從index.html連結進入abc.html#1頁面 : 然後照順序#1 > #2 > #3 : 翻頁下去 : 當我翻到#3時,按瀏覽器的上一頁鍵,會回到#2 : 請問有辦法可以讓它回到index.html嗎? 用jQuery寫的簡單例子 $('body').on('click', 'a', function(e) { var href = $(this).attr('href'), bookmark = href.match(/#(.*)/); if (bookmark && bookmark[1]) { e.preventDefault(); location.replace('#' + bookmark[1]); } }); 取消點上連結後的瀏覽器預設動作 然後以replace取代現有網址 防止書籤連結進入網頁歷史紀錄 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.190.145 ※ 編輯: mrbigmouth 來自: 122.116.190.145 (12/19 13:36)

12/19 20:23, , 1F
感謝你! 我會自己再多研究看看的
12/19 20:23, 1F
文章代碼(AID): #1GqIyR15 (Ajax)
討論串 (同標題文章)
文章代碼(AID): #1GqIyR15 (Ajax)