jsFiddle: Cleaning Copy/Paste Input for ContentEditable
- April 2, 2015 9:46 AM
- Comments (2)
This is captured in an AngularJS directive, but the process could easily be bound with jQuery instead and follow the same steps. The basics here are to stop the default paste, read the paste data as plain text, and then to replace some risky characters (necessary for my exact use case).
As noted, this example has been built for and tested in Chrome only - I know for IE, you need to potentially handle a different getData() operation.
while copying and pasting a content i should have all the formatting on the text as in its original page.. bt it shouldnt paste images
That library allows you to specify allowed tags that should be copied over. This would let you leave in bold and strong tags while pulling out images. Unfortunately, I'm not sure you can guarantee that the formatting is exactly the same depending on the source you are pasting from into the editable HTML, due to differences in the systems, but you should be able to maintain some of the formatting.