How to Prevent Pasting into an Input
Every once in a while I get to a website that doesn't allow me to paste into a form input. In most cases it's something to do with login credentials (username and or password) and auth codes. So how are they preventing me from pasting information? It's as easy as you'd think!
Let's start with the input
element:
<input type="text" onpaste="return false;" ondrop="return false;" autocomplete="off" />
The onpaste
attribute lets us prevent pasting into the form. Adding the autocomplete
attribute as well as preventing drag and drop into the element. If you want to avoid the on{event}
code in the HTML, you can do it the cleaner way:
myElement.addEventListener('paste', e => e.preventDefault());
Writing this post pains me because I loathe when websites prevent me from pasting text. I'm begging you not to do this. Just don't.
![CSS Animations Between Media Queries]()
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...
![5 Ways that CSS and JavaScript Interact That You May Not Know About]()
CSS and JavaScript: the lines seemingly get blurred by each browser release. They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely. We have our .js files and our .css, but...
![Create Twitter-Style Dropdowns Using jQuery]()
Twitter does some great stuff with JavaScript. What I really appreciate about what they do is that there aren't any epic JS functionalities -- they're all simple touches. One of those simple touches is the "Login" dropdown on their homepage. I've taken...
![Introducing MooTools ScrollSpy]()
I've been excited to release this plugin for a long time. MooTools ScrollSpy is a unique but simple MooTools plugin that listens to page scrolling and fires events based on where the user has scrolled to in the page. Now you can fire specific...
So am I able to edit the locally stored js file to re-enable pasting until I reload the page?
Thanks a lot for sharing this. It was really needed as I don’t like to write passwords and username again and again.