preserve动态的后退按钮更改HTML [英] Preserve dynamically changed HTML on back button

查看:88
本文介绍了preserve动态的后退按钮更改HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是惊人的,我经常看到其他网站,但从来没有在我的工作地点这一工作。

It's amazing, I constantly see this working in other sites but never in sites that I'm working on.

我带来新的内容与阿贾克斯,我知道history.js和历史API,我不想改变的网址,只需在浏览器缓存中的新的HTML内容,这样,当用户离开该页面并谈到使用后退按钮回来,它仍然有更新的HTML。

I'm bringing in new content with ajax, I know about history.js and the History API, I do not want to change the URL, just have the browser cache the new HTML content so when a user leaves the page and comes back using the back button, it still has the updated HTML.

我看到这个工作在其他网站所有的时间而不改变URL或使用散列#。
有一招,得到它的工作,或者它被浏览器随机决定的?
如果我不希望使用的网址有这个信息,有一个简单的方法吗?

I see this working all the time in other sites without URL changes or using the hash #.
Is there a trick to get it to work or is it randomly decided by the browser?
If I don't want to use the URL to have this information, is there an easy alternative?

推荐答案

有关十年半的现在,我已经用我曾经发现的痛苦的反复试验两个技巧是:输入字段值 - 特别是隐藏的人 - 是$ P $连同该URL pserved在浏览器的历史记录 - 与 - onLoad事件时由背面(或前向)钮返回到页面调用。

For about a decade and half now, I have been using two tricks that I once discovered by painful trial and error: Input field values - especially 'hidden' ones - are preserved in the browser's history along with the URL - AND - the onLoad event is called when returning to the page by the back (or forward) buttons.

这意味着你可以存储多达国家,只要你喜欢 - 在隐藏字段(记得把它们放在一种形式),然后重新开的onLoad的变化。我通常做渲染的一部分单独的功能......换句话说,在该动态性正在发生的时候,我第一次写的隐藏字段 - 然后调用渲染功能。然后,我召集所有的各种渲染功能动态性的各个位,距离的onLoad调用它们。

This means that you can store as much 'state' as you like - in hidden fields (remember to put them in a form), and then 'redo' the changes on 'onLoad'. I usually make the 'render' part a separate function... In other words, at the time that the dynamicness is occurring, I first write to the hidden fields - then call the render function. Then I gather together all the various render functions for the various bits of dynamicness and call them from the onLoad.

我要强调,我从来没有去过任何手册打猎这一点 - 所以不能提供任何保证, - 但我一直在使用它可靠了好一会儿(因为网景!)它与多的浏览器(所有的IE,铬,FF - 但至于其他人,我从来没有尝试过)

I would stress that I have never gone hunting for this in any manuals - so cannot offer any assurances - but I have been using it reliably for a good while (since Netscape!!!) It works with 'many' browsers (all the IEs, chrome, FF - but as for the others, I've never tried.)

如果任何人有更多的'正确' - 少乏味 - 的方式,我来说,我会很高兴听到这件事。但是,这似乎这样的伎俩。

If anyone has a more 'correct' - and less tedious - way, I for one, will be very glad to hear about it. But this does seem to do the trick.

这篇关于preserve动态的后退按钮更改HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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