<input style='position:absolute;margin-left: -1000px;' type="text" value="Угу!" id="myInput">
<button onclick="myFunction('УГУ!')">Скопировать текст УГУ! в буфер</button>


function myFunction(val) {
  var copyText = document.getElementById("myInput");
  copyText.value =val;
  copyText.select();
  document.execCommand("copy");
  alert("Текст в буфере : " + copyText.value);
}




External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.