簡體   English   中英

如何將iframe的格式化html轉換為純文本?

[英]How to get/convert formatted html of iframe into plain text?

我創建了一個iframe,可以在其中發布格式化的文本(例如,從Word文檔中)並以html格式接收。 是否還可以接收未格式化的版本(沒有html標記),例如在將格式化文本復制到文本區域時創建的版本?

我用於記錄格式化文本html的代碼:

<!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>

從技術上講,我可以要求用戶也將格式化的文本粘貼到單獨的textarea框中,但是我希望一次完成。

提前致謝

試試這個var text = editor.body.innerText || editor.body.textContent; var text = editor.body.innerText || editor.body.textContent;

從此答案中獲取https://stackoverflow.com/a/6743966/2668119

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM