Скопировать текст: различия между версиями
Материал из ВикиВоины
Строка 1: | Строка 1: | ||
+ | <button class="button text-copy-button" onclick="copyText()">Скопировать текст</button> | ||
+ | <script> | ||
function copyText() { | function copyText() { | ||
var textToCopy = document.getElementById("text-copy").innerText; | var textToCopy = document.getElementById("text-copy").innerText; | ||
Строка 9: | Строка 11: | ||
}); | }); | ||
} | } | ||
+ | </script> |
Версия 14:59, 8 мая 2024
<button class="button text-copy-button" onclick="copyText()">Скопировать текст</button> <script> function copyText() {
var textToCopy = document.getElementById("text-copy").innerText; navigator.clipboard.writeText(textToCopy) .then(() => { alert("Текст скопирован!"); }) .catch(err => { console.error('Ошибка копирования: ', err); });
} </script>