Disable browser 'Save Password' functionality

前端 未结 30 3390
失恋的感觉
失恋的感觉 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-21 23:59

    I have tested that adding autocomplete="off" in form tag in all major browsers. In fact, Most of the peoples in US using IE8 so far.

    1. IE8, IE9, IE10, Firefox, Safari are works fine.

      Browser not asking "save password". Also, previously saved username & password not populated.

    2. Chrome & IE 11 not supporting the autocomplete="off" feature
    3. FF supporting the autocomplete="off". but sometimes existing saved credentials are populated.

    Updated on June 11, 2014

    Finally, below is a cross browser solution using javascript and it is working fine in all browsers.

    Need to remove "form" tag in login form. After client side validation, put that credentials in hidden form and submit it.

    Also, add two methods. one for validation "validateLogin()" and another for listening enter event while click enter in textbox/password/button "checkAndSubmit()". because now login form does not have a form tag, so enter event not working here.

    HTML

    Username: Password:

    Javascript

    //For validation- you can modify as you like
    function validateAndLogin(){
      var username = document.getElementById("username");
      var password = document.getElementById("password");
    
      if(username  && username.value == ''){
        alert("Please enter username!");
        return false;
      }
    
      if(password && password.value == ''){
        alert("Please enter password!");
        return false;
      }
    
      document.getElementById("hidden_username").value = username.value;
      document.getElementById("hidden_password").value = password.value;
      document.getElementById("HiddenLoginForm").submit();
    }
    
    //For enter event
    function checkAndSubmit(e) {
     if (e.keyCode == 13) {
       validateAndLogin();
     }
    }
    

    Good luck!!!

提交回复
热议问题