如何停用Chrome自动填充功能(2020年之后) [英] How to disable Chrome autofill (after 2020)

查看:503
本文介绍了如何停用Chrome自动填充功能(2020年之后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近几次偶然发现此问题,Chrome忽略了autocomplete="false"autocomplete="off".如果有人提交了带有随机"hack"字样的表格,它甚至会忽略autocomplete="whatever"或您为欺骗它所做的任何事情.在它之前.

I've stumbled across this issue a couple of times in the last while, where Chrome ignores autocomplete="false" and autocomplete="off". It will now even ignore autocomplete="whatever" or anything you do to trick it, if someone has submitted a form with that random "hack" in it before.

在尝试解决此问题时,我遇到了此StackOverflow问题,该问题无法解决如果您之前提交过包含此字段的表单,则会出现问题.

In trying to solve this issue, I came across this StackOverflow question, which doesn't solve the problem if you've submitted a form containing this field before.

这不适用于密码字段.

推荐答案

答案是?动态更改页面加载时的nameautocomplete值.无论您使用什么,都可以通过PHP,JS来完成此操作.就我而言,我在PHP中通过向nameautocomplete值添加时间戳(以秒为单位)来完成此操作:

The answer? Dynamically change the name and autocomplete values on page load. You can do this via PHP, JS, whatever you're using. In my case, I've done this in PHP by adding a timestamp (in seconds) to the name and autocomplete values:

<input type="text" id="example" name="whatever<?php echo time(); ?>" autocomplete="whatever<?php echo time(); ?>">

变为:

<input type="text" id="example" name="whatever1525376494" autocomplete="whatever1525376494">

这将确保Chrome不会在每次加载新页面时自动提出建议.

This will ensure that Chrome doesn't autosuggest with every new page load.

就我而言,这还不够,因为我多次提交了相同的表单而没有重新加载页面,并且大多数用户都将这样做.这意味着每次提交表单后,我都必须更改名称和自动填充值.

In my case, this wasn't enough, because I submit the same form multiple times without reloading the page, and most users will be doing the same. And this means I have to change the name and autocomplete values after each form submission.

为了解决这个问题,我添加了这部分JS来解决它.每隔2.5秒就会在这些值的末尾添加一个增量整数,以覆盖该整数.

To solve this, I added this bit of JS to get around it. It adds an incremental integer to the end of these values every 2.5 seconds, which covers it.

if ($('#example').length) {
  var dynamicName = $('#example').attr('name');
  var dynamicCounter = 0;
  setInterval(function(){
    var dynamicVal = dynamicName + dynamicCounter;
    $('#example').attr('autocomplete', dynamicVal).attr('name', dynamicVal);
    dynamicCounter += 1;
  }, 2500);
}

希望有帮助!

这篇关于如何停用Chrome自动填充功能(2020年之后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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