5

I'd like to capture the pasted html in both mozilla and ie and then, before the paste event occurs, I'd like to modify it. Any suggestions?

Shaokan
  • 7,438
  • 15
  • 56
  • 80
  • 1
    hope this isnt to any evil ends? – trickwallett Apr 22 '11 at 12:11
  • lol. I'm building my own wysiwyg editor and it's to have sane results when people paste stuff on the editor. For instance, I'd like to remove all those font tags that ie generates while pasting, or those style attributes which both browsers generate :) – Shaokan Apr 22 '11 at 12:14

2 Answers2

4

You can do it, but it's hacky. You have to essentially redirect the paste to an off-screen element. Here's my answer to a similar question: JavaScript get clipboard data on paste event (Cross browser)

Community
  • 1
  • 1
Tim Down
  • 318,141
  • 75
  • 454
  • 536
2

Here's a small - neat - jQuery snippet for the capturing Cut/Copy/Paste events:

$("#Text1").bind('cut copy paste', function(e) {
    alert(e.type + ' text!'); //Alerts the Cut/Copy/Paste event        
});

Source: http://www.devcurry.com/2009/07/detect-copy-paste-and-cut-operations-on.html

Viral Jain
  • 1,004
  • 1
  • 14
  • 30
  • In a fit of extreme laziness, I fill the event handler with "setTimeout($(e.target).change(), 0);", since my change event already handles all sanitization. Of course, ours is an internal tool, so has no client exposure. – Griffin Oct 07 '14 at 14:36