Html autocomplete= off 在 chrome 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31612867/
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
autocomplete= off not working in chrome
提问by Archit
We are working on one web application in that one payment page is there.
我们正在开发一个 Web 应用程序,其中有一个支付页面。
In that we have two Text box one is for Credit Card Number and second one is for Verification Code and it type="Password".
因为我们有两个文本框,一个是信用卡号,第二个是验证码,输入=“密码”。
Now problem is when page is load in google-chrome it found type="Password" it load Save email id in Credit Card Textbox and password in Verification Code.
现在的问题是,当页面在 google-chrome 中加载时,它发现 type="Password" 它加载 Save email id in Credit Card Textbox and password in Verification Code。
Now try to solve this issue i was try out something like below.
现在尝试解决这个问题,我正在尝试类似下面的方法。
<form autocomplete="off">
<asp:textbox autocomplete="off">
This above try is not work for me. i was googling it but by luck it's not work for me.
以上尝试对我不起作用。我在谷歌上搜索它,但幸运的是它对我不起作用。
回答by Darren Willows
It appears that Chrome now ignores autocomplete="off" unless it is on the <form autocomplete="off">
tag since v34.
看来 Chrome 现在会忽略 autocomplete="off" 除非它<form autocomplete="off">
自 v34 以来在标签上。
you can't cheat by create an hidden input over. Auto complete feature will get the first input text to fill data.
你不能通过创建一个隐藏的输入来作弊。自动完成功能将获取第一个输入文本以填充数据。
Method 1:
方法一:
<form id="" method="post" action="" autocomplete="off">
<input type="text" style="display:none" />
<input type="password" style="display:none">
<asp:textbox autocomplete="off">
</form>
So put this before your textbox.
所以把它放在你的文本框之前。
<input type="text" style="display:none" />
Method 2:
方法二:
Change
改变
autocomplete="off"
to
到
autocomplete="false"
Method 3:Browser autofill in by readonly-mode.
方法 3:浏览器通过只读模式自动填充。
<input type="password" readonly onfocus="this.removeAttribute('readonly');"/>
Method 4:
方法四:
For username password combinations. Chrome heuristics looks for the pattern.
对于用户名密码组合。Chrome 启发式方法会寻找模式。
<input type="text" onfocus="this.type='password'">
Method 5:jQuery
方法五:jQuery
if ($.browser.webkit) {
$('input[name="password"]').attr('autocomplete', 'off');
$('input[name="email"]').attr('autocomplete', 'off');
}
回答by Edy Prasetyo
this is works if you want to keep white as your input background color
如果您想保持白色作为输入背景色,这是可行的
<input type="password" class="form-control" id="password" name="password" placeholder="Password" readonly onfocus="this.removeAttribute('readonly');" style="background-color: white;">
回答by Vahid Alvandi
use this solution
使用此解决方案
<input type="password" class="form-control auto-complete-off" id="password" name="password" autocomplete="new-password">
回答by jatin sorathiya
Chrome does not support autocomplete="off" at the form level for some input fields. There are 2 solutions to do so:
对于某些输入字段,Chrome 在表单级别不支持 autocomplete="off"。有两种解决方案:
In your form, if only two or three fields ignore autocomplete="off", then use the field name itself as the autocomplete value. i.e. autocomplete=
<form:input type="text" id="name" path="name" autocomplete="name"/>
Instead of defining field name manually for each field, use a script for all text typed input at the loading of the page or after.
if ($.browser.chrome) { $(document).on('focus click tap', 'input', function() { $(this).attr("autocomplete", 'block'); }); } else { $(document).on('focus click tap', 'input', function() { $(this).attr("autocomplete", 'off'); }); }
在您的表单中,如果只有两个或三个字段忽略 autocomplete="off",则使用字段名称本身作为自动完成值。即自动完成=
<form:input type="text" id="name" path="name" autocomplete="name"/>
不要为每个字段手动定义字段名称,而是在页面加载时或之后为所有输入的文本使用脚本。
if ($.browser.chrome) { $(document).on('focus click tap', 'input', function() { $(this).attr("autocomplete", 'block'); }); } else { $(document).on('focus click tap', 'input', function() { $(this).attr("autocomplete", 'off'); }); }
回答by Gabor
This works well and also compatible with MDL (Material Design Light):
这很好用,并且与 MDL(材料设计灯)兼容:
// Fix chrome's ignore on autocomplete=off
$('input[autocomplete=off]').each(function(){
var copy = $(this).clone();
copy.val('');
copy.removeAttr('autocomplete');
copy.insertAfter($(this));
$(this).hide().removeAttr('required id class');
});
回答by Gabor
automcomplete="off" or automcomplete="false"
or Define autocomplete inside Input field
或在输入字段内定义自动完成
$('input[name="password"]').attr('autocomplete', 'off');//Disable cache