动态dom操作后如何在浏览器历史记录中保留dom状态? [英] How do I preserve dom state in the browser history after dynamic dom manipulation?

查看:151
本文介绍了动态dom操作后如何在浏览器历史记录中保留dom状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在用于保留dom状态的通用解决方案,以便当用户使用后退/前进返回页面时,整个页面处于他们离开页面的确切状态?

Is there a general purpose solution for preserving dom state so that when a user returns to a page by using back/forward, the whole page is in the exact state that they left it?

这篇文章问并回答了为什么行为与不同的浏览器和不同的javascript库不一致...

This post asks and answers why the behavior is inconsistent with different browsers and different javascript libraries...

Ajax,后退按钮和DOM更新

...但我很好奇是否有人可以解决此问题,而无需重新加载页面。

...but I am curious if anyone has a general solution to this problem that doesn't require reloading the page.

推荐答案

Rails中的这种缓存清除技术使其可以在现代浏览器(chrome,ie8 +,ff 3.5+)中运行。这对我的上一个项目很有效,当时我们进行了ajax更新dom的操作,并且不得不向后导航并保持ajax更新。

You can use this cache busting technique in rails to make it work in modern browsers (chrome, ie8+, ff 3.5+). This worked for me on my last project when we had ajax update the dom and had to navigate back and have the ajax updates persist.

response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"

这篇关于动态dom操作后如何在浏览器历史记录中保留dom状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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