1

Firstly I would just like to thank everyone for reading this and answering my questions. The help given to date has been invaluable and I a better programmer thanks to the help I have been given.

To the problem at hand. I fear it is a little rough but the script below for the most part works.

The problem is that while the history is stored, when a user goes back or forward the page doesn't change. Do you have any idea what I can do to modify this so the go function is triggered?

$(document).ready(function(){

 $("a").click(function() {
  if (strpos($(this).attr('href'), 'mob.php') !== false) {
   window.location = url($(this).attr('href'));
   go(idToPath($(this).attr('href')));
   return false;
  }
 });
});

function go(num) {
 if (num != undefined) {
  $.ajax({
   url: "mob.php?p="+num+"&logo=0",
   cache: false,
   success: function(html){
    $("#ajax").html(html);
   }
  });
 }
}

$.history.init(function(u) {});
var page = 4;
var id = window.location.hash.substr(1);
if (id != '' && page != id) {
 go(id);
}
4

3 回答 3

1

没有这样的事件。

但是你可以使用一些历史插件,看看它是如何在那里完成的:http: //www.mikage.to/jquery/jquery_history.html

于 2010-06-22T08:18:14.417 回答
0

好吧,我不确定这个问题的任何固定解决方案。

但我想出了一个临时解决方案。

  1. 在通过 Ajax 导航的每个页面的开头,我都会存储页面信息和其他参数。喜欢$_SESSION['page'][] = "book.php?cat=1"
  2. 将函数附加到浏览器的历史事件并调用自定义函数来获取所需的 URL 并重定向到它。

这不是一个答案,但这应该给你一个粗略的想法。:)

于 2010-06-22T08:17:04.140 回答
0

将 ajax 添加到浏览器状态的组合会导致许多复杂的问题,如下所述: 如何在 URL 中显示 Ajax 请求?

jQuery Ajaxy项目是使用 ajax 和浏览器状态的一个很好的开始。

于 2010-09-18T11:55:08.827 回答