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?
-
1hope this isnt to any evil ends?trickwallett– trickwallett2011-04-22 12:11:39 +00:00Commented Apr 22, 2011 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– Shaokan2011-04-22 12:14:55 +00:00Commented Apr 22, 2011 at 12:14
Add a comment
|
2 Answers
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)
Comments
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
1 Comment
Griffin
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.