Giter Site home page Giter Site logo

appkad / jquery.disableautofill Goto Github PK

View Code? Open in Web Editor NEW

This project forked from terrylinooo/disableautofill.js

0.0 1.0 0.0 903 KB

Disable form auto-fill and auto-complete functions.

Home Page: https://terrylinooo.github.io/jquery.disableAutoFill/

License: MIT License

JavaScript 100.00%

jquery.disableautofill's Introduction

jquery.disableAutoFill

The easiest solution for disabling Google Chrome auto-fill, auto-complete functions.

Document Transations: English | 繁體中文 | 简体中文


I've spent serveral hours surfing online to look for solutions in order to disable Google Chrome auto-fill, auto-complate functions such as the screenshot below.

Image

After having tried all possible solutions I can find on Stackoverflow, howerver, they are outdated and not working. Finally I figured out that Google Chrome forces dropping the submission history while a form contains type="password" field, so this plugin is to do the following steps:

  • Replace type="password" to type="text" and then replace the text with asterisks.
  • Add an attribute autocomplete="off" on form.
  • Randomize the input name value to prevent Chrome or other third-party extensions to remember what you filled.

Install

Npm

npm install disableautofill

Bower

bower install jquery.disableAutoFill

CDN

<script src="https://cdn.jsdelivr.net/npm/disableautofill/src/jquery.disableAutoFill.min.js"></script>

Demo

Check out the demo page to see how it works.

Usage

HTML

<form id="login-form">

JS

$('#login-form').disableAutoFill();

Options

option default note
passwordField - Dom Element by ID or by ClassName, if not set, disableAutoFill will automaticlly pick up the [type=password] field.
submitButton - Dom Element by ID or by ClassName, if not set, disableAutoFill will automaticlly pick up the [type=submit] button.
hidingChar Character use to hide real password value.
debugMode false If true, printing form serialized data in console log instead of submitting.
randomizeInputName true This plugin will randomize input name attribute by default. It will restore back to original field name when submitting form. This is for preventing auto completion for all browsers (includes third-party auto-completeion extensions) not just for Google Chrome.
html5FormValidate false Set this option to "true" to enable HTML 5 native form validate ( required,pattern etc...)
callback - To validate form fields or something you can do.

Example

$('#login-form').disableAutoFill({
    passwordField: '.password',
    callback: function() {
        return checkForm();
    }
});

function checkForm() {
    form = document.getElementById('login-form');
    if (form.password.value == '') {
        alert('Cannot leave Password field blank.');
        form.password.focus();
        return false;
    }
    if (form.username.value == '') {
        alert('Cannot leave User Id field blank.');
        form.username.focus();
        return false;
    }
    return true;
}

Suggestion

This plugin may not work while the javascript render speed is slow. Chrome detects the type="password" and still assign the "remember me" to the form elements.

You can modify the input type="password" to "text", and add a class (for example: ".password")

<input type="text" name="password" class="password">
$(function() {
    $('.login-form').disableAutoFill({
        passwordField: '.password'
    });
});

https://jsfiddle.net/terrylinooo/hhgzbsvy/

License

MIT

Authors

jquery.disableautofill's People

Contributors

terrylinooo avatar bmendonca avatar berry120 avatar ssebs avatar felly avatar zamabraga avatar brenard avatar tommyduggs avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.