Re: [問題] url hash上一頁鍵的問題
※ 引述《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
討論串 (同標題文章)
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章