Chrome禁用自動(dòng)填充autocomplete="off"無(wú)效

通常情況下,如果不希望輸入框自動(dòng)填充,可以給input設(shè)置autocomplete="off"

但是當(dāng)輸入框type="password"時(shí),第一次填寫時(shí)Chrome會(huì)提示是否保存密碼。如果保存了密碼,下次打開時(shí)Chrome會(huì)自動(dòng)填充密碼輸入框,并用保存的用戶名或郵箱填充在密碼輸入框之前的任意輸入框。

這是因?yàn)?,Chrome會(huì)忽視密碼輸入框的autocomplete="off"。針對(duì)Chrome這個(gè)問題,可以使用以下解決辦法。
測(cè)試用Chrome版本:Version 58.0.3029.110。

可能可行的方法:添加隱藏的input

在用戶名和密碼輸入框之前,添加兩個(gè)隱藏的輸入框。

<input style="display:none" type="text" name="fakeusernameremembered"/>
<input style="display:none" type="password" name="fakepasswordremembered"/>

我嘗試了這種方法,但還是自動(dòng)填充......如果不隱藏是可行的,但不能不隱藏??!這種方法可能適用舊版本的Chrome吧。

可行方法:改autocomplete的值

type="password"input中添加autocomplete="new-password"。有點(diǎn)莫名奇妙,但真的好用。這個(gè)方法在Chrome開發(fā)者的討論中被提到:

Comment 7 by gcasto@chromium.org ,
May 16 2014
The distinction for Autofill vs. Password Autofill is basically who does the filling, not the type of text field. For sites that use e-mail address for usernames, Autofill might want to allow you to select from known e-mail addresses (which can be disabled via autocomplete=off) while Password Autofill might want to fill with a username for this site (which can't be disabled). If both features want to put suggestions in the same field, Password Autofill wins.
In any case, ignoring autocomplete=off is intended. It's not clear from your question if you think that this also shouldn't fill because the markup is different between the two forms. We use this as one indication for filling, but not the only one. Signup forms and login forms may have slightly different markup, but if you save your password during signup we still want to fill it when you log in.
However, we are working on being smarter about when to fill, including not filling on password forms that require confirmation ( issue 352347 ). You could/should also mark these fields with autocomplete="new-password". This attribute was very recently added to the spec, but we should have support for it by M37. It would also prevent filling in this case (though we would still save the password if it was updated).</pre>

看Stackflow上有建議autocomplete="false"的,可以試試。

參考閱讀:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容