How do I disable the save password bubble in chrome using Javascript?

前端 未结 13 1875
不思量自难忘°
不思量自难忘° 2020-11-27 19:56

I need to be able to prevent the Save Password bubble from even showing up after a user logs in.

Autocomplete=off is not the answer.

I have not come across a

相关标签:
13条回答
  • 2020-11-27 20:39

    Add <input type="password" style="display:none"/> to the top of your form. Chrome's autocomplete will fill in the first password input it finds, and the input before that, so with this trick it will only fill in an invisible input that doesn't matter.

    0 讨论(0)
  • 2020-11-27 20:42

    The only thing worked for me was adding a space to input's value after document ready and then deleting the space when user focused on the input.

    $('.login-input').val(' ');
    $('.login-input').on('focus', function() {
        $(this).val('');
    });
    

    Simple and easy. Works on Chrome 64. In Firefox all you need is adding autocomplete="off" attribute to the input.

    0 讨论(0)
  • 2020-11-27 20:44

    I've subverted this by using 2 regular text boxes. One to contain the actual password and one to function as a mask. I then set the password box's opacity to 0 and the mask text box is disabled - but the background color is set to white making it appear enabled. Then I place the password box on top of the mask box. In a jscript function I update the mask's text value to display a string of '*' characters with each keypress in the password box. Two drawbacks: the blinking cursor might now show depending on your browser. It shows in IE, but not Chrome or Firefox. There's a bit of a delay as the user is typing.

    My code snippet is in asp:

    $(window).ready(function() {
      var pw = $('#txtPassword');
      var mask = $('#txtMask');
      $(pw).css('opacity', '0');
      $(pw).keyup(function() {
        var s = '';
        for (var i = 0; i < $(pw).val().length; i++)
          s = s + '*';
        mask.val(s);
      })
    });
    style... .password {
      font-family: monospace;
      position: absolute;
      background-color: white;
    }
    Asp.net code:
    <asp:TextBox runat="server" CssClass="password" Width="300" ID="txtMask" ClientIDMode="Static" MaxLength="30" Enabled="false" />
    <asp:TextBox runat="server" CssClass="password" Width="300" ID="txtPassword" ClientIDMode="Static" MaxLength="30" />

    0 讨论(0)
  • 2020-11-27 20:46

    My own solution jQuery with PrimeFaces. Tested work in Chrome and Internet Explorer but in mozilla firefox (though not in Firefox)

    <script  type="text/javascript" charset="utf-8">
    $(function(){
        $('#frmLogin').on('submit',function(e){
    
            $(PrimeFaces.escapeClientId('frmLogin:usuario')).replaceWith('<label id="frmLogin:usuario1" type="text" name="frmLogin:usuario1" autocomplete="off" class="form-control" maxlength="8"  tabindex="2"/>');
            $(PrimeFaces.escapeClientId('frmLogin:password')).replaceWith('<label id="frmLogin:password1" type="password" name="frmLogin:password1" autocomplete="off" value="" tabindex="3" class="form-control"/>');
            $(PrimeFaces.escapeClientId('frmLogin:password1')).attr("autocomplete","off");
            $(PrimeFaces.escapeClientId('frmLogin:usuario1')).attr("autocomplete","off");
            $(PrimeFaces.escapeClientId('frmLogin:password_hid')).attr("autocomplete","off");
            $(PrimeFaces.escapeClientId('frmLogin:usuario_hid')).attr("autocomplete","off");
    
        });
    });
    </script>
    

    <h:inputSecret id="password" value="#{loginMB.password}" class="form-control" 
        placeholder="Contraseña" tabindex="3"  label="Contraseña" autocomplete="off" disabled="#{loginMB.bdisabled}"/>
        <p:inputText value="#{loginMB.password_hid}" id="password_hid" type="hidden" />
    
    0 讨论(0)
  • 2020-11-27 20:49

    I found there is no "supported" way to do it.

    What I did was copy the password content to a hidden field and remove the password inputs BEFORE submit.

    Since there aren't any passwords fields on the page when the submit occurs, the browser never asks to save it.

    Here's my javascript code (using jquery):

    function executeAdjustment(){       
            $("#vPassword").val($("#txtPassword").val());
            $(":password").remove();        
            var myForm = document.getElementById("createServerForm");
            myForm.action = "executeCreditAdjustment.do";
            myForm.submit();
        }
    
    0 讨论(0)
  • 2020-11-27 20:49
    <input type="textbox" id="UserID" />
    <input type="password" style="display:none"/>
    <input type="textbox" id="password" />
    
    <script>
      function init() {
           $('#password').replaceWith('<input type="password" id="password" />');
      }     
    </script>
    

    tested in Firefox and chrome working as expected.

    0 讨论(0)
提交回复
热议问题