Created
June 4, 2020 20:07
-
-
Save raysuelzer/e3e95ee8f8ada598496f47367fededee to your computer and use it in GitHub Desktop.
Autocomplete disabling hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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