Html 如何防止浏览器缓存表单字段?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9587201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:57:49  来源:igfitidea点击:

How to prevent browser from caching form fields?

htmlformsautocompletebrowser-cache

提问by Igor

I have a textboxin a form field that gets populated by the user. However currently (in Firefox 10) the user can navigate away from the page, then come back, and the input will be populated with its previous value. I think this creates for a confusing user experience, and would like to prevent it.

我有一个textbox由用户填充的表单字段。但是目前(在 Firefox 10 中)用户可以离开页面,然后返回,并且输入将填充其先前的值。我认为这会造成令人困惑的用户体验,并希望阻止它。

Is there a way to do this without manually resetting the value? I have tried changing the response to not cache as well as setting autocomplete='false'with no luck.

有没有办法在不手动重置值的情况下做到这一点?我曾尝试将响应更改为不缓存以及autocomplete='false'没有运气的设置。

回答by soju

Try with autocomplete="off", but it will not work with all browsers

尝试使用autocomplete="off",但它不适用于所有浏览器

PS: duplicate...

PS:重复...

Stop browser from filling textboxes with details

阻止浏览器用详细信息填充文本框

Make page to tell browser not to cache/preserve input values

制作页面以告诉浏览器不要缓存/保留输入值

回答by A.T.

just add simple script in some global JS:

只需在一些全局 JS 中添加简单的脚本:

$("form :input").attr("autocomplete", "off");

回答by Hossein Hajizadeh

use meta in head

在头中使用元

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">

or Use

或使用

<% Response.CacheControl = "no-cache"; %>
<% Response.AddHeader("Pragma", "no-cache"); %>
<% Response.Expires = -1; %>

microsoft

微软