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?

2
  • 1
    hope this isnt to any evil ends? Commented 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 :) Commented Apr 22, 2011 at 12:14

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.