How to stop Chrome from autocompleting text areas?

半腔热情 提交于 2020-08-24 08:18:05

问题


I am dealing with a text area in part of a contact form that Chrome wants to autofill with the user's address. As a result many contact requests are submitted by users with their address in the comment field. Besides the obvious potential security issues that could be exploited, my concern is that from a user's standpoint we're providing a contact form without an area to type a message. And from a support standpoint, we're having to ask users to send us another message with their actual question.

HTML:

 <textarea id="element_10" class="validate[required] floatlabel js-auto-size multiple-lines" name="element_10" placeholder="Message*" rows="10" cols="60" required autocomplete="off"></textarea>

回答1:


Answering my own question since I did not find the answer on Stack or in any Chrome browser docs.

In some cases, the browser will keep suggesting autocompletion values even if the autocomplete attribute is set to off. This unexpected behavior can be quite puzzling for developers. The trick to really forcing the no-autocompletion is to assign a random string to the attribute, for example:

autocomplete="nope"

Since this random value is not a valid one, the browser will give up.

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion




回答2:


I tried all the suggestions and nothing really worked consistently.

If I set one input to autocomplete="nope" it works.

If I set two or more it breaks them all.

If I set two to autocomplete="nope" and autocomplete="no" it works on those two but breaks again if I do anything to a 3rd.

My form only has 3 inputs. I just set email and phone and left name alone. That pretty much solves my problem.

I have some jquery validation that pretty much does not work with autocomplete and this client really does not want to be bothered with junk emails.

Also Chrome treats a one row textarea exactly the same as a input.



来源:https://stackoverflow.com/questions/43217431/how-to-stop-chrome-from-autocompleting-text-areas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!