Disable browser 'Save Password' functionality

前端 未结 30 3364
失恋的感觉
失恋的感觉 2020-11-21 23:29

One of the joys of working for a government healthcare agency is having to deal with all of the paranoia around dealing with PHI (Protected Health Information). Don\'t get m

30条回答
  •  醉梦人生
    2020-11-22 00:00

    Because autocomplete="off" does not work for password fields, one must rely on javascript. Here's a simple solution based on answers found here.

    Add the attribute data-password-autocomplete="off" to your password field:

    
    

    Include the following JS:

    $(function(){
        $('[data-password-autocomplete="off"]').each(function() {
            $(this).prop('type', 'text');
            $('').hide().insertBefore(this);
            $(this).focus(function() {
                $(this).prop('type', 'password');
            });
        });     
    });
    

    This solution works for both Chrome and FF.

提交回复
热议问题