Enabling copy and paste on sites which block it

If I had to make a list of website habits which annoy me the most, sites which prevent me from pasting values into forms would be high on the list (I’m old enough to remember when disabling right-clicks was also a thing, to prevent users from saving images).

Fortunately there’s a simple way to workaround this by opening the developer toolbar in Chrome or Firefox and entering the following code:

var allowPaste = function(e){
  e.stopImmediatePropagation();
  return true;
};
document.addEventListener('paste', allowPaste, true);

The above code registers a function that will be run whenever the ‘paste’ event is triggered, i.e. when the browser detects that you have tried to paste content into the current web page. When run, the function prevents any other event listeners from being run. Since listeners are run in the reverse order of when they were registered (last registered, first run), the code that disables pasting will never be called, and so you will be able to paste to your heart’s content – at least until you move to another page.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.