Membuat tombol copy text dengan html, CSS dan javascript

 <textarea id="copyText" >snshsh</textarea>



<button type="button" id="copyButton">Copy</button>


<style type="text/css">

#copyButton {

  background-color: #4CAF50;

  color: white;

  padding: 15px 32px;

  text-align: center;

  text-decoration: none;

  display: inline-block;

  font-size: 16px;

  font-weight: bold;

  border-radius: 8px;

  border: none;

}


</style>



<script type="text/javascript">

// Get the text field

var copyText = document.getElementById("copyText");


// Get the button

var copyButton = document.getElementById("copyButton");


// When the user clicks the button, execute the function

copyButton.addEventListener("click", function() {

  // Copy the text inside the text field

  copyText.select();

  copyText.setSelectionRange(0, 99999); /*For mobile devices*/

  

  /* Copy the text inside the text field */

  document.execCommand("copy");

  

  // Alert the copied text

  alert("Copied the text: " + copyText.value);

});


</script>

Posting Komentar

Lebih baru Lebih lama

Formulir Kontak