Allow the browser to support jquery ajax load forward and backward Functions

Source: Internet
Author: User

BEGIN;


Most people do not consider the need for the browser to support the forward and backward functions when doing ajax load, because most people do not know how to implement it.

I recently encountered this problem. After a short study, I found that github has already been used as an open-source tool. The main implementation principle is to use the html anchor, that is, <a href = "# xxx">, view https://github.com/balupton/jquery-history/tree/master for details


The main demo code is as follows:

Html

<ul><li><a href="#ttt">ttttttttttttttt</a></li><li><a href="#aaa">aaaaaaaaaaaaaaa</a></li><li><a href="#bbb">bbbbbbbbbbbbbbb</a></li><li><a href="#eee">eeeeeeeeeeeeeee</a></li><li><a href="#mmm">mmmmmmmmmmmmmmm</a></li></ul><div id="showdiv" style="width: 500px; height: 500px; border: 1px groove #e3e7ea;">default content</div>
Js

<Script type = "text/javascript"> $ (function () {// This is a shared location. perform operations using the state parameter $. history. bind (function (state) {$ ('# showdiv '). load ('Action/'{state}'.html ') ;}); // here is a special operation on a link $. history. bind ('bbb ', function (state) {alert ('click the bbb link, which is a special processing location for the bbb link') ;}); </script>

Related questions:

State parameter: the xxx value in the hyperlink tag href = "# xxx.

Execution sequence: perform special operations before performing shared operations.


The detailed source code is as follows:

Http://download.csdn.net/detail/cyzshenzhen/7487091 (csdn) Resources

Git @ OSC source code hosting address: http://git.oschina.net/cyzshenzhen/jquery_history_demo


END;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.