AJAX -- 使用 jQuery.history 解決「上一頁」問題

AJAX

簡介

方法

jQuery

REST

問與答

上一頁問題

搜尋問題

訊息

相關網站

參考文獻

最新修改

簡體版

English

使用 jQuery Plugin

<script type="text/javascript" src="jquery.history.js"></script>
...
<script type="text/javascript">
 
// 「上一頁」觸發後執行的函數
function pageload(hash) {
    // 根據傳回的 hash(錨點),AJAX 置換顯示的內容
    if(hash) {
        // 重新讀取指定頁面
        $("#load").load(hash + ".html");
    } else {
        // 如果沒有回傳值,代表已經回到 AJAX 的初始狀態頁,清空顯示的內容
        $("#load").empty();
    }
}
 
$(function () {
    // 初始化 history plugin,並設定回傳使用的函數
    $.historyInit(pageload);
 
    // 設定觸發寫入歷史紀錄條件的按鈕事件
    $("a[rel='history']").click(function(){ // 取得超連結的錨點
        var hash = this.href;
        hash = hash.replace(/^.*#/, ''); // 點選 AJAX 頁面時,紀錄位置於瀏覽器的歷史紀錄中
        $.historyLoad(hash);
        return false;
    });
});
</script>

參考文獻

  1. [jQuery Plugin] jquery.history AJAX 無法回到上一頁的解決方案 — http://hi.baidu.com/lifa868/blog/item/91a2f7f16ce9eac97831aabd.html/cmtid/fe6c0f0be0172033b0351da8

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License