如何像 Facebook 一样在照片库中保留浏览器历史记录?

发布于 2024-10-08 08:38:39 字数 587 浏览 0 评论 0原文

我正在开发一个使用ajax的照片库。我也在使用 _escaped_fragment_ (#!),它已经可以工作了,但是当您使用后退和前进浏览器按钮时,网址会更改(哈希片段),但图像不会更改't。我读到了关于 onHashChange 事件的内容,但我想知道是否有一种自动方法可以做到这一点,我的意思是,是否有一种方法可以像 Facebook 那样在历史记录中保留 DOM 更改。

我用以下方法更改哈希片段:

window.location.hash = "!"+sth

我加载ajax内容检索哈希片段并将其用作我的照片的索引:

var fragment = window.location.hash.replace("#!","");
if (fragment != ""){
  currentItem = fragment;
  currentItemBZ = fragment-1;
  focused = currentItemBZ;
}

任何帮助或建议将不胜感激

I'm developing a photo gallery that uses ajax. I'm using _escaped_fragment_ (#!) too, it already works but when you use the back and fwd browser buttons the url change (the hash fragment) but the image doesn't. I read about the onHashChange event but i wanto to know if there's an automatic way to do this, i mean, if there's a way to preserve the DOM changes in the history just like Facebook does.

I change the hash fragment with:

window.location.hash = "!"+sth

I load ajax content retrieving the hash fragment and using it as index of my photo:

var fragment = window.location.hash.replace("#!","");
if (fragment != ""){
  currentItem = fragment;
  currentItemBZ = fragment-1;
  focused = currentItemBZ;
}

Any help or suggestion will be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声情话 2024-10-15 08:38:39

我过去使用过这个 jQuery 插件在基于 ajax 的应用程序中保留后退按钮和历史记录功能:

http://www.asual.com/jquery/address/

您可以注册一个更改监听器,然后根据新的哈希值更改图库中的图像。

I've used this jQuery plugin in the past to retain back-button and history functionality in an ajax-based application:

http://www.asual.com/jquery/address/

You can register an on change listener, and then change the image in your gallery depending on the new value of the hash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文