javascript – 使用ajax并将html数据保存为对象时,聆听浏览器后退按钮.是好是坏?

栏目: Html · 发布时间: 5年前

内容简介:似乎pjax是您正在寻找的图书馆:翻译自:https://stackoverflow.com/questions/12359895/listening-to-browser-back-button-when-using-ajax-and-saving-the-html-data-as-an
我正在创建一个脚本,用于监听浏览器后退按钮并加载上一页.我是jquery和 javascript

(一个 php 人)的新手.在重新发明之前,我已经在整个网络上搜索了一个库.但是由于我在ajax链接中使用了很多参数,我无法使用这些库.我承认我的错误,因为我不知道如何使用这种复杂的系统.所以我在想如果创建一个系统如下.

// get the contents of a particular div and save as an object/associative array 
// { hash : pageNumber, html : content}
function save_history(div){
    var content = $(div).html();
    // increment the page number and add hash tags to the URL
}   

// Listen to the browser hash value change
$(window).bind('hashchange', function () {
    hash = window.location.hash;
    if(hashValue){
        load_history(hashValue);
    }   
}); 

// Load data from history
function load_history(id){
    // fetch the content based on the hashvalue
    $(div).html(content);
}

使用它有什么问题吗?当许多内容被保存为对象时,这会使页面无响应或崩溃浏览器吗?如果它导致这样的问题,我不想浪费我的时间.

似乎pjax是您正在寻找的图书馆: https://github.com/defunkt/jquery-pjax

翻译自:https://stackoverflow.com/questions/12359895/listening-to-browser-back-button-when-using-ajax-and-saving-the-html-data-as-an


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Visual C++网络通信协议分析与应用实现

Visual C++网络通信协议分析与应用实现

汪晓平、钟军 / 人民邮电出版社 / 2003-2-1 / 60.00元

本书介绍了如何利用Visual一起来看看 《Visual C++网络通信协议分析与应用实现》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具