--- url: "https://web.dev/articles/clipboard/paste-text/pattern" titulek: "web.dev" h1: "" popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/clipboard/paste-text/pattern" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 02:40:59" znaku: 1725 slov: 203 kodovani: "iso-8859-2" sha256: "5214700b72ab0b3875a3131c2692409517970271cda7fb96d73fc11f4a0dff73" --- Stay organized with collections Save and categorize content based on your preferences. HTML `
` CSS `:root { color-scheme: dark light; } html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } body { margin: 1rem; font-family: system-ui, sans-serif; } button { display: block; }` JS `const pasteButton = document.querySelector('button'); pasteButton.addEventListener('click', async () => { try { const text = await navigator.clipboard.readText() document.querySelector('textarea').value += text; console.log('Text pasted.'); } catch (error) { console.log('Failed to read clipboard. Using execCommand instead.'); document.querySelector('textarea').focus(); const result = document.execCommand('paste') console.log('document.execCommand result: ', result); } });` Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2026-07-29 UTC.