Skip to content

Instantly share code, notes, and snippets.

@TravelingTechGuy
Last active August 9, 2016 19:55
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 TravelingTechGuy/69e86d6f3e26d60a53536abe4046d35d to your computer and use it in GitHub Desktop.
Save TravelingTechGuy/69e86d6f3e26d60a53536abe4046d35d to your computer and use it in GitHub Desktop.
Disable paste event
//1. Plain JavaScript
document.getElementById("txtPassword").addEventListener("paste", function(e) {
e.preventDefault();
});
//2. If jQuery is used on the page, it might look like this:
$('#txtPassword').bind("paste", function(e) {
e.preventDefault();
});
//3. Sometimes, event and function are separate:
document.getElementById("txtPassword").addEventListener("paste", preventPaste);
//...later in the file...
function preventPaste(e) {
e.preventDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment