Answers for "create copy button html"

2

copy button value to clipboard function javascript

//U need to have a button with the id the same as its name because it is going to be sent to the clipborad.
/*Like this: */
<button onClick="SelfCopy(this.id)"  id="1">1</button>
<button onClick="SelfCopy(this.id)"  id="2">2</button>
<button onClick="SelfCopy(this.id)"  id="3">3</button>

function SelfCopy(copyText)
  {
      navigator.clipboard.writeText(copyText);
      alert("You just copied this: (" + copyText + ").");
  }
Posted by: Guest on April-24-2021
1

copy to clipboard button hide

<body>
    <button onclick="setClipboard('test')">Ativar Conexão</button>
    
<script>
function setClipboard(value) {
    var tempInput = document.createElement("input");
    tempInput.style = "position: absolute; left: -1000px; top: -1000px";
    tempInput.value = value;
    document.body.appendChild(tempInput);
    tempInput.select();
    document.execCommand("copy");
    document.body.removeChild(tempInput);
}
</script>
Posted by: Guest on January-23-2021
0

html copy button

HTML:
<!-- The text field -->
<input type="text" value="Hello World" id="myInput">

<!-- The button used to copy the text -->
<button onclick="myFunction()">Copy text</button>

JAVASCRIPT:
function myFunction() {
  /* Get the text field */
  var copyText = document.getElementById("myInput");

  /* Select the text field */
  copyText.select();
  copyText.setSelectionRange(0, 99999); /* For mobile devices */

   /* Copy the text inside the text field */
  navigator.clipboard.writeText(copyText.value);

  /* Alert the copied text */
  alert("Copied the text: " + copyText.value);
}
Posted by: Guest on February-24-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language