阻止浏览器记住密码功能

一、关于浏览器记住密码功能

可以参考:http://www.cnblogs.com/tianma3798/p/6062869.html

二、如何控制浏览器不提示“是否记住密码”呢

解决方案1:

1.关闭表单的自动完成功能 autocomplete=off(这一条针对表单自动完成),关于参考:autocomplete属性

2.延迟设置密码域,即在页面加载成功后 将输入框的type=‘password’

注:window.onload 事件对于现在360浏览器好像没起作用,解决办法是再使用settimeout 等待一段时间执行

代码示例:

    <div class="container">
        <form action="form1.html" autocomplete="off" id="formOne">
            <div class="form-group">
                <label>用户名</label>
                <input type="text" autocomplete="off" class="form-control" name="UserName" />
            </div>
            <div class="form-group">
                <label>密码</label>
                <input id="Pwd" class="form-control" name="Pwd" />
            </div>
            <input class="btn btn-default" type="submit" />
        </form>
    </div>
    <script>
        window.onload= function () {
           setTimeOut(function(){
        var pwd = document.getElementById('Pwd');
            pwd.type = "password";
      },200);
        }
    </script>

解决方案2:

不使用浏览器的默认的密码域,自己封装一个。

当前参考文章:http://www.jb51.net/article/35878.htm

 

posted @ 2016-11-14 18:47  天马3798  阅读(3634)  评论(0编辑  收藏  举报