如何禁止谷歌浏览器自动填充密码

版权声明:本文为博主原创文章,如若转载请注明博客来源以及地址,多谢 https://blog.csdn.net/xiaoluodecai/article/details/53190489

参考网址:Disabling Chrome Autofill

问题所在:

谷歌浏览器会自动填充密码,某方面是很方便,但是也会出现意想不到的效果,比如填充的颜色变成黄色,可能与设计不符,主要原因是浏览器给input加上了一个样式:

input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
    background-color: rgb(250, 255, 189);
    background-image: none;
    color: rgb(0, 0, 0);
}

解决方法其一可以是覆盖浏览器的样式。但,我们可以尝试更加高大上的解决办法:

解决办法:

在旧版的谷歌浏览器中,可以使用以下方法:

<form autocomplete="off">

对于整个表单生效;

<input autocomplete="off">

对于单个input生效;

在新版的谷歌浏览器中,autocomplete=”off”已经失效,需要尝试以下方法:

<!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
<input style="display:none" type="text" name="fakeusernameremembered"/>
<input style="display:none" type="password" name="fakepasswordremembered"/>

用法是在form表单的加入这两句代码,然后name需要改成将要禁止填充的input。其原理是,谷歌浏览器会自动填充这个input,而不会填充你代码中实际展示的input,从而绕过谷歌浏览器的自动填充功能;

猜你喜欢

转载自blog.csdn.net/xiaoluodecai/article/details/53190489