Search code examples
javascriptjquerycontenteditablepasterangy

using Rangy.js to paste plain text without HTML tags


I tied to search and search around here and Google, But i not found any solution to do it so simple via using Rangy.js or native JS.

If I have simple formatted text to copy like..

<div>
    <b>Copy me (All) : Soufflé chupa chups</b><br>
    <p style="color:#f00;">
        Cotton candy caramels
    </p>
</div>

How can I copy and paste plain text (without styled text) to contenteditable element ?

I dont care about older IEs. Just current Firefox or Chrome need to work.

Demo : http://jsfiddle.net/72r6J/


Solution

  • Unfortunately you'll need a slightly hacky solution. I've described it here:

    https://stackoverflow.com/a/3554615/96100

    Here's a helpful in-depth answer to a similar question by a CKEditor developer:

    Paste as plain text Contenteditable div & textarea (word/excel...)