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">
The main demo code is as follows:
Html
Copy codeThe Code is as follows:
<Ul>
<Li> <a href = "# ttt"> ttttttttttttttt </a> </li>
<Li> <a href = "# aaa"> aaaaaaaaaaaaa </a> </li>
<Li> <a href = "# bbb"> bbbbbbbbbbbbbbb </a> </li>
<Li> <a href = "# eee"> eeeeeeeeeeeeeee </a> </li>
<Li> <a href = "# mmm"> mmmmmmmmmmm </a> </li>
</Ul>
<Div id = "showdiv" style = "width: 500px; height: 500px; border: 1px groove # e3e7ea;"> default content </div>
Js
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Function (){
// This is a shared location, which is operated by 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.