制作页面以告诉浏览器不要缓存/保留输入值 [英] Make page to tell browser not to cache/preserve input values

查看:30
本文介绍了制作页面以告诉浏览器不要缓存/保留输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数浏览器缓存表单输入值.因此,当用户刷新页面时,输入具有相同的值.

Most browsers cache form input values. So when the user refreshes a page, the inputs have the same values.

这是我的问题.当用户点击保存时,服务器会验证 POSTed 数据(例如检查的产品),如果无效,则将其发送回浏览器.但是,如上所述,即使服务器清除了某些值的选择,由于浏览器缓存,它们仍然可能被选中!

Here's my problem. When a user clicks Save, the server validates POSTed data (e.g. checked products), and if not valid, sends it back to the browser. However, as stated above, even if the server clears selection for some values, they may still be selected because of the browser cache!

我的数据有不可见的(直到选择父项)复选框,因此用户甚至可能不知道某些先前的值仍然被选中,直到再次单击保存并收到错误消息 - 即使用户认为不是.这很烦人.

My data has invisible (until parent item selected) checkboxes, so the user may be even not aware that some previous value is still selected, until clicking Save again and gets an error message - even though the user thinks it's not. Which is irritating.

这可以通过执行 Ctrl + F5 来解决,但这甚至不是解决方案.是否有一种自动/编程方式告诉浏览器不要在某些表单/页面上缓存表单输入数据?

This can be resolved by doing Ctrl + F5, but it's not even a solution. Is there an automatic/programmatic way to tell browser not to cache form input data on some form/page?

推荐答案

您是否将值明确设置为空白?例如:

Are you explicitly setting the values as blank? For example:

<input type="text" name="textfield" value="">

这应该会阻止浏览器将数据放在不该放的地方.或者,您可以将 autocomplete 属性添加到表单标签:

That should stop browsers putting data in where it shouldn't. Alternatively, you can add the autocomplete attribute to the form tag:

<form autocomplete="off" ...></form>

这篇关于制作页面以告诉浏览器不要缓存/保留输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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