Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

573
Visualizações
How do I allow copy-pasting of HTML tables into an HTML textarea tag?

TinyMCE, CKEditor, and Froala allow you to copy-paste HTML tables (e.g. from an email or Wikipedia) directly into the HTML textarea and the HTML table structure and tags are preserved.

For an additional example, my web-based email client can also do this. I can copy an HTML table from an email I received into an email I am sending, and the table structure will be preserved.

I understand that these editors are not just HTML textareas, rather they are rich text editors. My question: What browser capabilities allow for rich text editing? How do they do this?

From what I can tell, every time I copy-paste some HTML into a textarea, the browser strips out all HTML tags.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The answer is that HTML is very flexible and you aren't limited to the default behavior of input elements for user interaction. Specifically how it handles non plaintext paste, the answer is it isn't simple.

Luckily there are a few open source rich text editors. For example, in ckeditor it is handled by the clipboard pipeline which takes the paste event and applies the correct styling in the editor.

about 4 years ago · Juan Pablo Isaza Relatório

0

Here's a minimal answer. Thank you to Andrew Gillis for directing me to the CKEditor source code that had something similar.

<html>
    <head>
    </head>
    <body>
        <textarea class="rich" cols="40" rows="8"></textarea>
    </body>

    <script>
        const target = document.querySelector('textarea.rich');
        target.addEventListener('paste', (event) => {
            const clipboard_data = (event.clipboardData || window.clipboardData);
            const text_paste_content = clipboard_data.getData('text/plain');
            const html_paste_content = clipboard_data.getData('text/html');

            // This what we see by default
            console.log(text_paste_content)

            // This is the raw HTML that can be used to make "rich" content
            console.log(html_paste_content)
        });
    </script>
</html>

When you paste into the textarea, you will have access to the raw HTML through the html_paste_content variable.

about 4 years ago · Juan Pablo Isaza Relatório

0

Often these editors will have a user-visible <div> element as the element that renders the table and a hidden <textarea> element that contains the actual markup that will be sent to the server when the form is submitted.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda