Undoing oncut/oncopy/onpaste Falsities

Published 9 years, 1 week past

Inspired by Ryan Joy’s excellent and deservedly popular tweet, I wrote a small, not-terribly-smart Javascript function to undo cut/copy/paste blocking in HTML.

function fixCCP() {
   var elems = document.getElementsByTagName('*');
   var attrs = ['onpaste','oncopy','oncut'];
   for (i = 0; i < elems.length; i++) {
      for (j = 0; j < attrs.length; j++) {
         if (elems[i].getAttribute(attrs[j])) {
            .replace("return false","return true"));

Here it is as a bookmarklet, if you still roll that way (as I do): fixCCP.  Thanks to the Bookmarklet Maker at bookmarklets.org for helping me out with that!

If there are obvious improvements to be made to its functionality, let me know and I’ll throw it up on Github.

Comments (4)

  1. Nice, but I don’t think it will work if the CCP blocking is implemented as something like this:


  2. Yeah, it skips event listeners entirely (thus “blocking in HTML”). I went for fast and cheap. If there’s a good universal way to deal with listeners too, I’m happy to add it!

  3. Maybe listen to the event in the “capture” phase and override
    e.preventDefault to an empty function?

    ['cut', 'copy', 'paste'].forEach(function(name) {
    window.addEventListener(name, function(event) {
    event.preventDefault = function() {};
    }, true);

    I didn’t try on a website that _really_ was doing this. Also this won’t work if they do it in a iframe of course.

  4. Pingback ::

    Article Roundup - Hoverboard Studios

    […] Undoing oncut/oncopy/onpaste Falsities […]

Add Your Thoughts

Meyerweb dot com reserves the right to edit or remove any comment, especially when abusive or irrelevant to the topic at hand.

HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <em> <i> <q cite=""> <s> <strong> <pre class=""> <kbd>

if you’re satisfied with it.

Comment Preview