SO的形式如何记住之前的输入值? [英] How does SO's form remember previous input values?

查看:130
本文介绍了SO的形式如何记住之前的输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,如果我回到 问题 标题 Body 部分会被记住>按钮,然后按下 返回 按钮。



此功能适用于我测试过的所有浏览器,对于我自己的项目中的表单不存在。



我该如何解决这个问题?

UPDATE



我还没有任何线索,但猜测某些客户端缓存是由http头还是javascript支持的? p>

解决方案

它与页面的缓存属性有关。

1)如果允许浏览器缓存页面,它也会记住表单域。 2)如果不允许缓存页面,它将会忘记一切。



通常,动态生成的页面属于类别2,因此您看不到缓存。
这实际上是由HTTP标头确定的(特别是Cache-Control和Last-Modified,或使用电子标签
)。有关您的浏览器如何确定缓存(非平凡!)的解释,请参阅: performance / caching-http-headers-last-modified-and-etag.htmlrel =noreferrer> http://www.webscalingblog.com/performance/caching-http-headers-last-modified-and-etag。 html



但最简单的方法是将表单放在一个静态HTML页面上,然后您的web服务器将处理所有内容。


I've noticed that the Title or Body part is remembered if I come back to the Ask Question page by pressing Back button of my browser.

This feature is available in all browsers I tested, but doesn't exist for the forms in my own projects.

How can I approach that effect?

UPDATE

I still don't have any clue yet,but guess it that some kind of client cache enabled by http headers or javascript?

解决方案

It has to do with the caching properties of your page.

1) If the browser is allowed to cache your page, it will also remember the form fields.

2) If it is not allowed to cache the page, it will forget everything.

Usually, dynamically generated pages fall into category 2, hence you don't see the caching. This is indeed determined by HTTP headers (especially Cache-Control and Last-Modified, or using E-Tags ). For an explanation on how your browser determines caching (non-trivial!), see for example:

http://www.webscalingblog.com/performance/caching-http-headers-last-modified-and-etag.html

But easiest is to put the form on a static HTML page, then your webserver will handle everything.

这篇关于SO的形式如何记住之前的输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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