从javascript检测浏览器自动完成设置

时间:2012-09-25 08:20:24

标签: javascript jquery

有什么办法,我们可以从客户端脚本中检测自动完成的浏览器设置吗?不同的浏览器具有差异自动完成设置。

我想根据自动填充功能的客户端浏览器设置将autocomplete =“off”添加到文本字段中。

1 个答案:

答案 0 :(得分:1)

为什么不把它谷歌给我的朋友.....

http://help.dottoro.com/ljdwgiwh.php

Example Code:

在用户名和城市字段中填写一些文字内容,然后提交表格 之后,开始用相同的内容填充这些字段。将在用户名字段中显示自动完成窗口。

  <head>
    <script type="text/javascript">
        function DisableAutoComp () {
            var username = document.getElementById ("username");
            if ('autocomplete' in username) {
                username.autocomplete = "off";
            }
            else {
                    // Firefox
                username.setAttribute ("autocomplete", "off");
            }
        }
    </script>
</head>
<body>
    Fill the user name and city fields with some text content, and submit the form.<br />
    After that, start to fill these fields with the same content. An autocomplete window will displayed for to the user name field.
    <br /><br />
    <form method="post" action="#URL#">
        User name, with autocompletion:
        <input type="text" id="username" name="username" autocomplete="on" />
        <br />
        City, without autocompletion:
        <input type="text" name="city" autocomplete="off" />

        <br /><br />
        <input type="submit" value="Send" />
    </form>
    <br />
    <button onclick="DisableAutoComp ();">Disable autocompletion!</button>
</body>