0

I created an iframe into which I can post formatted text (from a Word document for example) and receive it as html. Is it possible to also recieve the unformatted version (without the html tags), such as created when copying formatted text into a textarea?

My code for logging the html of formatted text:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <script>
        window.addEventListener("load", function () {
            var editor = theWYSIWYG.document;
            editor.designMode = 'on';
            action.addEventListener('click', function() {
                var formattedHTML = editor.body.innerHTML
                console.log(formattedHTML);
            }, false)
        }, false)
    </script>
</head>
<body>
    <div id="textEditor">
        <button id="action" title="Bold"><b>Click me</b></button>
        <div id="richTextArea"></div>
            <iframe id="theWYSIWYG" name="theWYSIWYG" frameborder="0"></iframe>
    </div>
</body>
</html>

Technically I could ask the user to also paste the formatted text into a seperate textarea box, but I would prefer to do it in a single time.

Thanks in advance

sir-haver
  • 3,096
  • 7
  • 41
  • 85

1 Answers1

1

Try this var text = editor.body.innerText || editor.body.textContent;

Taken from this answer https://stackoverflow.com/a/6743966/2668119

DGS
  • 6,015
  • 1
  • 21
  • 37
  • I'm thinking whether I should delete this question since it's easy to find an answer so it was my bad for not finding it – sir-haver Jan 24 '19 at 03:06