Html autocomplete = 'off' 在 Firefox 上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17781077/
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' is not working on firefox
提问by Deepak Kumar Padhy
I am facing a browser issue:
我面临浏览器问题:
I created 2 login pages of same domain.
我创建了 2 个相同域的登录页面。
- www.example.com/login.cfm
- www.example.com/newLogin.cfm
- www.example.com/login.cfm
- www.example.com/newLogin.cfm
I put the form name different for 2 forms with in these two page. Also I put autocomplete = 'off'
for the second form and for the text fields within that form.(But it is on for first form ).
我在这两个页面中为 2 个表单添加了不同的表单名称。我还autocomplete = 'off'
为第二个表单和该表单中的文本字段设置了。(但它是为第一个表单打开的)。
Now if I save the username and password at the time of login from www.testDomain.com/login.cfm
in browser, then the list of usernames are auto populating in the username field of second login page even if the auto Complete is off. I need to block this for security reasons. Is there any way to do this? I am using FireFox V21.
现在,如果我在从www.testDomain.com/login.cfm
浏览器登录时保存用户名和密码,那么即使自动完成关闭,用户名列表也会自动填充在第二个登录页面的用户名字段中。出于安全原因,我需要阻止它。有没有办法做到这一点?我正在使用 FireFox V21。
回答by albert.garipov
$("#CVV").on("focusout", function() {
if ($(this).val() == "") {
$(this).attr("type", "text");
}
});
<input type="text" name="username" class="input" ID="CVV" onfocus="removeErr('CVV'); $(this).attr('type', 'password');">
回答by Bob The Janitor
This is the cleanest solution I have found to keep Firefox from auto completing.
这是我发现的最干净的解决方案,可以防止 Firefox 自动完成。
<!-- The text and password here are to prevent FF from auto filling my login credentials because it ignores autocomplete="off"-->
<input type="text" style="display:none">
<input type="password" style="display:none">
Add this code snip-it above your input of type password.
在您输入的密码类型上方添加此代码片段。
As far as I can tell Firefox is looking for an input of type Password, and filling in the password and then adding the username to the input of type text above it. Without a name or an id the inputs don't get added to the post, but this is still a hack.
据我所知,Firefox 正在寻找类型为 Password 的输入,并填写密码,然后将用户名添加到其上方的文本类型的输入中。没有名称或 id,输入不会被添加到帖子中,但这仍然是一个 hack。
回答by PulsarFox
You all should try this attribute :
你们都应该试试这个属性:
<input type="password" autocomplete="new-password" />
<input type="password" autocomplete="new-password" />
回答by Darko Tasevski
Firefox version 61 this seems to be enough to disable autocomplete in forms:
Firefox 版本 61 这似乎足以禁用表单中的自动完成功能:
<input type="password" hidden />
All inputs after this one at the top of the form are ignored.
表单顶部此输入之后的所有输入都将被忽略。
回答by Cataclysm
I was encountered this issue for a long time. Firefox was kept input values even page reload. Setting autocomplete
attribute to off
did not solve.
我遇到这个问题很长时间了。即使页面重新加载,Firefox 也会保留输入值。设置autocomplete
属性off
没有解决。
Form caching is a really useful mechanism for the user experience. But, in the small percentage of use-cases like translating values of textboxes or texareas to other language, these gave me headache.
表单缓存对于用户体验来说是一种非常有用的机制。但是,在少数用例中,例如将文本框或 texareas 的值翻译成其他语言,这些让我头疼。
To resolve this, just simply reset the form after page was loaded as
要解决此问题,只需在页面加载后重置表单即可
$('form').trigger("reset");
回答by zavero.kris
回答by RicardoVallejo
Nothing worked for me for the password field so I'll share my trick
密码字段对我没有任何作用,所以我将分享我的技巧
<input name="password" type="text" onkeydown="this.type='password'">
I believe it is still secure and works on Chrome, Firefox, other
我相信它仍然安全并且适用于 Chrome、Firefox 和其他
回答by Taylan
Just put a random value in autocomplete.
只需在自动完成中放置一个随机值。
<input autocomplete = "!!1337!!">
回答by lucas
I tried all of the above with Firefox 52 and nothing worked. I did get it to work with jQuery though and replacing the value with the original value, or:
我在 Firefox 52 上尝试了上述所有方法,但没有任何效果。我确实让它与 jQuery 一起工作,并用原始值替换了该值,或者:
jQuery(window).load( function () {
email = jQuery('#auth_user_email');
email.prop('value', email.attr('value'));
});
where in jQuery the prop is the current value in the document and attr is the original when the document is first retrieved/loaded. I used the load function because it runs after the ready function and I believe definitely after the autocomplete overwrites the input value. you can do the same thing with the password input also.
在 jQuery 中,prop 是文档中的当前值,而 attr 是第一次检索/加载文档时的原始值。我使用 load 函数是因为它在 ready 函数之后运行,我相信在自动完成覆盖输入值之后肯定会。你也可以用密码输入做同样的事情。
回答by CPJ
A way to Firefox don't find those fields is to change their type to hidden before the post.
Firefox 找不到这些字段的一种方法是在帖子之前将它们的类型更改为隐藏。
You can use a jQuery or JavaScript to set that on onclientclick in your submit button.
您可以使用 jQuery 或 JavaScript 在提交按钮中的 onclientclick 上进行设置。
Example:
<script type="text/javascript">
function setHidden() { $('.input').prop('type', 'hidden'); }
</script>
例子:
<script type="text/javascript">
function setHidden() { $('.input').prop('type', 'hidden'); }
</script>
<input type="text" name="username" class="input">
<input type="password" name="password" class="input" >
<asp:Button ID="ubtnLogin" Text='OK' runat="server" OnClick="btnLogin_Click" OnClientClick='setHidden();' />
Just remember to clear your browser's cache before testing or use the private mode (CTRL+SHIFT+P).
请记住在测试或使用私有模式 (CTRL+SHIFT+P) 之前清除浏览器的缓存。