【问题标题】:Autocomplete attribute of html is working on local machine but when i deploy it on server then it doesn't workhtml的自动完成属性在本地机器上工作,但是当我将它部署在服务器上时它不起作用
【发布时间】:2019-07-03 20:17:44
【问题描述】:

我想通过使用 autocomplete="off" 来禁用网络浏览器的自动完成功能。我尝试使用此属性并且在我的本地机器上工作正常但是当我在服务器上部署相同的代码并且当我使用本地机器的浏览器访问相同的页面时(我之前确认的相同的 chrome 浏览器并按预期工作)似乎自动完成未禁用并提示保存用户名和密码。

<!DOCTYPE html>
<html>
<head>
    <title>Form, autocomplete html5</title>
</head>
<body>
    <form action="" autocomplete="off">
        <table>
            <tr>
                <td>
                    <label>First Name:</label>
                </td>
                <td>
                    <input type="text" name="fname">
                </td>
            </tr>
            <tr>
                <td>
                    <label>Last Name:</label>
                </td>
                <td>
                    <input type="text" name="lname">
                </td>
            </tr>
            <tr>
                <td>
                    <label>Email ID:</label>
                </td>
                <td>
                    <input type="text" name="email">
                </td>
            </tr>
            <tr>
                <td>
                    <label>Password:</label>
                </td>
                <td>
                    <input type="password" name="pwd">
                </td>

            </tr>
            <tr>
                <td> </td>
                <td>
                    <input type="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

我希望在通过将页面部署在服务器上使页面生效后为什么它不能工作并且在我的本地计算机上正常工作的确切原因。我的浏览器信息是“版本 75.0.3770.100(官方版本)(32 位)”。为了使它正确,可能需要采取哪些必要步骤。

【问题讨论】:

  • 尝试检查表单并检查服务器上已部署站点的属性
  • 我进行了检查,甚至该属性 autocomplete="off" 出现在浏览器中,但它仍然不起作用。虽然如果我在本地机器上运行此 html 运行良好,则进行相同的检查,但从服务器运行时,尽管在调试模式下出现 autocomplete="off",但相同的代码不遵守 autocomplete="off"。

标签: html


【解决方案1】:

如 MDN 关于自动完成的文章所述:

在大多数现代浏览器中,将自动完成设置为“关闭”不会阻止密码管理器询问用户是否要保存用户名和密码信息,或者自动在网站的登录表单中填写这些值。

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values

您可以通过将密码字段的自动完成属性设置为new-password 来解决此问题,如下所述:https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#Preventing_autofilling_with_autocompletenew-password

一般来说,我建议保留自动完成功能,因为在大多数情况下阻止用户使用除功能之外的功能会导致糟糕的用户体验。

【讨论】:

    【解决方案2】:

    我从下面给出的链接中获得了我的解决方案,并找到了一种摆脱浏览器询问用户 ID 和保存密码的方法。

    How to disable Chrome's saved password prompt setting through JavaScript

    此链接帮助我获得了预期的结果。

    【讨论】:

      猜你喜欢
      • 2022-06-10
      • 2016-07-21
      • 1970-01-01
      • 2017-04-10
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      相关资源
      最近更新 更多