Edit on
<html>
  <head></head>
  <body>
    <div id="contenteditable" contenteditable></div>
    <label>
      <input type="checkbox" id="toggle" checked>
      Toggle <code>contenteditable</code>
    </label>
    <p>Focus the frame, then paste using Control-V (⌘-V on Mac)</p>
    <div id="log"></div>
  </body>
</html>
#contenteditable {
  display: none;
}
document.addEventListener( 'paste', function( event ) {  
  var data = event.clipboardData,
      content, logEntry;

  if ( data.types[ 0 ] === 'text/plain' ) {
    content = data.getData( data.types[ 0 ] );
  } else {
    content = data.types[ 0 ];
  }
  
  logEntry = document.createElement( 'div' );
  logEntry.textContent = 'Paste detected! ' + content;
  document.getElementById( 'log' ).appendChild( logEntry );
} );

document.addEventListener( 'change', function( event ) {
  var contenteditable;
  
  if ( event.target.id !== 'toggle' ) {
    return;
  }
  
  contenteditable = document.getElementById( 'contenteditable' );
  
  if ( event.target.checked ) {
    contenteditable.setAttribute( 'contenteditable', '' );
  } else {
    contenteditable.removeAttribute( 'contenteditable' );
  }
} )
Rerun