简体   繁体   English

如何强制浏览器不缓存文本字段?

[英]How to FORCE the browser not to cache textfields?

Consider the login HTML page : 考虑登录HTML页面:

<%@ page language="java" 
    contentType="text/html; charset=windows-1256"
    pageEncoding="windows-1256"
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head><title>Bank application</title>
<link rel="stylesheet"
      href="./css/styles.css"
      type="text/css"/>

<link rel="stylesheet"
      href="./css/forgotPass.css"
      type="text/css"/>      
</head>

<body>
<table class="title">
  <tr><th>Web Bank application</th></tr>
</table>
<br/>


<!-- JS Code to make sure that the user MUST enter something in the login page -->
<script>
function verifyEmptyString()
{
    var username = document.forms["loginForm"]["username"].value;
    var password = document.forms["loginForm"]["password"].value;

    if (username == null || username == '' || password == null || password == '')
    {
        alert("Both Username and Password are required !");
        return false;
    }

    return true;
}     
</script>


<fieldset>
  <legend>Login Page - please enter your Username and Password</legend>

  <form onsubmit="return verifyEmptyString(this)" id="loginForm" action="loginPage" method="post" > 
  <!-- note we use here a paragraph & font size -->
  <!-- Notice we use a Required field !!! -->

    <p style="font-size:15px"><span style="color:red;font-weight:bold;">*</span> Username: <input type="text" name="username" value="" ><br> </p>
    <p style="font-size:15px"><span style="color:red;font-weight:bold;">*</span>  Password : <input type="password" name="password"><br> </p>
    <input type="submit" value="Login">

    <br> <br>
    <a href="#" class="myButton">Forgot your password ?</a>
  </form>
</fieldset>

<br/>
<br/>
<br/>
<br/>
<br/><br/><br/><br/><br/><br/>
</body></html>

The textfield of Username is always cached. Username的文本字段始终被缓存。

When I use : 当我使用时:

<input type="text" name="Username" autocomplete="off">

Then I get : Undefined attribute name (autocomplete) . 然后我得到: 未定义的属性名称(自动完成)

And that's also not supported in all the browsers . 而且也不是所有浏览器都支持。

How can I force completely the textfield from not remembering the previous values that were entered , in all the browsers ? 在所有浏览器中,如何才能完全不记住先前输入的值来强制文本字段?

Add this to your HTML : 将此添加到您的HTML中

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM