I have a basic editor based on execCommand following the sample introduced here. There are three ways to paste text within the execCommand area:
- Ctrl+V
- Right Click -> Paste
- Right Click -> Paste As Plain Text
I want to allow pasting only plain text without any HTML markup. How can I force the first two actions to paste Plain Text?
Possible Solution: The way I can think of is to set listener for keyup events for (Ctrl+V) and strip HTML tags before paste.
- Is it the best solution?
- Is it bulletproof to avoid any HTML markup in paste?
- How to add listener to Right Click -> Paste?
It will intercept the
pasteevent, cancel thepaste, and manually insert the text representation of the clipboard:http://jsfiddle.net/HBEzc/.
This should be the most reliable:
I’m not sure of cross-browser support, though.