Skip to content

Instantly share code, notes, and snippets.

@Mikescops
Last active August 31, 2021 07:36
Show Gist options
  • Save Mikescops/9a582d1b39b722dc3f19c952441822e4 to your computer and use it in GitHub Desktop.
Save Mikescops/9a582d1b39b722dc3f19c952441822e4 to your computer and use it in GitHub Desktop.
Prevent pasting in a field
<html>
<head>
<title>Experiment prevent pasting</title>
</head>
<body>
<h2>Login to your account</h2>
<p for="login">Login</p>
<input type="text" name="login" id="login" value="[email protected]" />
<p for="login">Password</p>
<input type="password" name="password" id="password" />
<script>
document.getElementById('password').addEventListener('paste', (event) => {
if (!confirm('You are pasting on a potential phishing website, continue?')) {
event.preventDefault();
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment