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.
I spent a few months experimenting with different approaches for writing simple, elegant and maintainable media queries with Sass. Each solution had something that I really liked, but I couldn't find one that covered everything I needed to do, so I ventured into creating my...
The HTML5 revolution has provided us some awesome JavaScript and HTML APIs. Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers. Regardless of API strength or purpose, anything to help us better do our job is a...
Zohaib Sibt-e-Hassan recently released a great mouse gestures library for MooTools called Moousture. Moousture allows you to trigger functionality by moving your mouse in specified custom patterns. Too illustrate Moousture's value, I've created an image download builder using Mooustures and PHP.
The XHTML
We provide...
One of the reasons I love AJAX technology so much is because it allows us to avoid unnecessary page loads. Why download the header, footer, and other static data multiple times if that specific data never changes? It's a waste of time, processing, and bandwidth. Unfortunately...
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.