How to Copy TEXT to Clipboard on Button-Click in HTML, JAVA

 

 

Welcome to We Shout Loud, Check Below for Code.
 
Step 1) Add (Place) HTML CODE below <body> Tag.
<– The text field –>
<input type=”text” value=”WeShoutLoud” id=”myInput”>
 Just Edit WeShoutLoud Text without (” “) as Your Text in above Line.
 
<– The button used to copy the text –>
<button onclick=”myFunction()”>Copy Text</button>
Just Edit Copy Text Text without (” “) as Your Text in above Line.
 
Step 2) Add (Place) JavaScript CODE below <body> Tag.
<script>
function myFunction() {
  var copyText = document.getElementById(“myInput”);
  copyText.select();
  document.execCommand(“Copy”);
  alert(“Copied the text: ” + copyText.value);
}
</script>
Share This:

Leave a Reply