Search code examples
javascripthtmljquerycss

How to turn off text box suggestions in Google Chrome using JavaScript


I was tried to prevent to store the username and password in Google Chrome password manager. so, I was changed the type password to text in the password field using following lines in jQuery in $(document).ready section.

     var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
    if (isChrome) {
        $("#UserPassword").attr("type", 'text');
        $("#UserPassword").attr("style", "-webkit-text-security:disc;");
    }
    else {
        $("#UserPassword").attr("type", 'password');
    }

but, I faced, some issue due to the address fill suggestion. it shows the already typed values in the suggestion. how to prevent show the suggestion in field or how prevent Google Chrome password manager to save the password from my site.

enter image description here

Enable Suggestion in Google Chrome:

  1. Open settings page in Google Chrome
  2. Select Autofill and password in left panel
  3. Then select the Addresses and more in Right Panel and enable the Save and fill addresses option.

Any one knows please give me suggestion for solve this issue


Solution

  • I am asked about autofill in field. i required for avoid show suggestion in that fields.

    Now, i got one solution for avoid this scenario.

    In the Suggestion show based on the field name.

    function formsubmit(e){
        e.preventdefault();
        $("#userpassword").attr("name","Password"");
        $("#loginform").submit();
    }
    
    
     <form action="/account/login" id="loginform" >
        <input type="text" name="123123124343_Password" id="userpassword"></input>
        <input type="submit" onclick="formsubmit()" value="Login"></input>
       </form>
    

    so,i was set the dynamic name for the field with unique id. in form submit event, i changed the field name as i required.

    Now, the suggestion box is not appeared in that field