Skip to content

Instantly share code, notes, and snippets.

@raysuelzer
Created June 4, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raysuelzer/e3e95ee8f8ada598496f47367fededee to your computer and use it in GitHub Desktop.
Save raysuelzer/e3e95ee8f8ada598496f47367fededee to your computer and use it in GitHub Desktop.
Autocomplete disabling hack
// Note: you would only want this to be executed once, and after
// the page has loaded. This is just a gist, it can be customized
// further
// Find all elements where autocomplete="off"
document.querySelectorAll('[autocomplete="off"]').forEach(
(element) => {
// Store the original name of the element
const orgininalName = element.getAttribute('name');
// When the item is focused, give the name attribute something
// random. This will, for now, will prevent autocomplete from being
// triggered
element.addEventListener('focus', () => {
// Or some other random name implementation
const randomName = Math.random().toString().replace('.', '');
element.setAttribute('name', randomName);
});
// When the element loses focus, set the name back to the original name
element.addEventListener('blur' , () => {
element.setAttribute('name', orgininalName);
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment