如何使用Ajax时保持浏览器历史记录同步? [英] How to keep the browser history in sync when using Ajax?

查看:454
本文介绍了如何使用Ajax时保持浏览器历史记录同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写使用ASP.NET AJAX一个简单的相册应用程序。
该应用程序使用异步Ajax调用,以pre-加载下一个相册中的照片,而无需改变URL在浏览器中。

I'm writing a simple photo album app using ASP.NET Ajax.
The app uses async Ajax calls to pre-load the next photo in the album, without changing the URL in the browser.

现在的问题是,当用户点击返回在浏览器按钮,应用程序不会再回到previous照片,相反,它定位到的主页应用程序。

The problem is that when the user clicks the back button in the browser, the app doesn't go back to the previous photo, instead, it navigates to the home page of the application.

有没有办法来欺骗浏览器将每个Ajax调用浏览历史记录?

Is there a way to trick the browser into adding each Ajax call to the browsing history?

推荐答案

更新:现在HTML5的历史API(pushState,popState),其中德precates的HTML4 hashchange 功能。 History.js 提供跨浏览器的兼容性和的可选 hashchange 回退HTML4浏览器。

Update: There is now the HTML5 History API (pushState, popState) which deprecates the HTML4 hashchange functionality. History.js provides cross-browser compatibility and an optional hashchange fallback for HTML4 browsers.

对于这个问题的答案将是或多或少一样我这些问题的答案:

The answer for this question will be more or less the same as my answers for these questions:

  • <一个href="http://stackoverflow.com/questions/3205900/how-to-show-ajax-requests-in-url/3276206#3276206">How显示在URL的Ajax请求?
  • <一个href="http://stackoverflow.com/questions/3460041/how-does-gmail-handle-back-forward-in-rich-javascript/3460269#3460269">How没有Gmail的处理前进/后退丰富的JavaScript?
  • How to show Ajax requests in URL?
  • How does Gmail handle back/forward in rich JavaScript?

总之,你一定要来看看这两个项目,其中解释整个hashchange过程,并添加AJAX的组合:

In summary, you'll definitely want to check out these two projects which explain the whole hashchange process and adding ajax to the mix:

  • jQuery History (using hashes to manage your pages state and bind to changes to update your page).

jQuery的Ajaxy (AJAX扩展jQuery的历史,以允许完全的AJAX网站而被完全不显眼和优雅降解的)。

jQuery Ajaxy (ajax extension for jQuery History, to allow for complete ajax websites while being completely unobtrusive and gracefully degradable).

这篇关于如何使用Ajax时保持浏览器历史记录同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆