【问题标题】:HTML - Attribute autocomplete="on" not working in Chrome browser [duplicate]HTML - 属性 autocomplete="on" 在 Chrome 浏览器中不起作用 [重复]
【发布时间】:2016-03-20 23:41:46
【问题描述】:

我在输入标签中添加了autocomplete="on"

<input autocomplete="on" type="email">

它在 Firefox 中运行良好,但在 Chrome 中却不行。我该如何解决这个问题?

【问题讨论】:

    标签: html google-chrome


    【解决方案1】:

    看来您需要为autocomplete 属性提供field-name

    <input autocomplete="email" type="email" />
    

    Chrome 有一些与之相关的设置,您可能需要启用这些设置。

    此外,由于某种原因,Chrome 似乎不允许 autocomplete="on"autocomplete="field-name",因为这是 Google 的一项安全决定,因此已经制作了一些扩展程序来支持它:

    来源的要点是:

    // Code design inspired by http://userscripts.org/scripts/show/7347 .  Not
    // overriding form submit prototypes like that does because I don't know of a
    // good way to do this with Isolated Worlds (see http://groups.google.com/
    // group/chromium-dev/browse_thread/thread/118689ceda861163/ff25578ed3585edd )
    // and I'm not sure the password manager would pick it up anyway (see comment
    // below).
    
    function enableAutocomplete()
    {
        var snapshot = document.evaluate('//@autocomplete',
            document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null),
            numItems = snapshot.snapshotLength - 1;
    
        for (var i = numItems; i >= 0; i--)
            snapshot.snapshotItem(i).nodeValue = 'on';
    }
    
    // The password manager code checks for "autocomplete=off" in a callback
    // from WebCore when the DOM content is loaded.  It doesn't seem to be
    // documented, but this callback seems to happen after in-page event listeners
    // fire, and before content scripts with "run_at" = "document_end" are loaded.
    // Therefore, we load this script early and then run the actual transform code
    // on an appropriate event listener.
    window.addEventListener('DOMContentLoaded', enableAutocomplete, false);
    

    上面记录的代码将使您能够像往常一样使用autocomplete

    更多信息请参考documentation

    【讨论】:

    • 我试过 不工作,密码和表单我检查了启用自动填充 -- 不适合我
    猜你喜欢
    • 2019-12-13
    • 2015-07-18
    • 2013-08-20
    • 2017-12-07
    • 2013-11-04
    • 2014-11-16
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多