Intercept the
paste
event, cancel the paste, and manually insert the text representation of the clipboard: http://jsfiddle.net/HBEzc/. This should be the most reliable:- It catches all kinds of pasting (Ctrl+V, context menu, etc.)
- It allows you to get the clipboard data directly as text, so you don't have to do ugly hacks to replace HTML
I'm not sure of cross-browser support, though.
editor.addEventListener("paste", function(e) {
// cancel paste
e.preventDefault();
// get text representation of clipboard
var text = e.clipboardData.getData("text/plain");
// insert text manually
document.execCommand("insertHTML", false, text);
});
0 comments:
Post a Comment