Answers for "copy to clipboard"

25

javascript text to clipboard

function copyToClipboard(text) {
   const elem = document.createElement('textarea');
   elem.value = text;
   document.body.appendChild(elem);
   elem.select();
   document.execCommand('copy');
   document.body.removeChild(elem);
}
Posted by: Guest on March-20-2020
11

js copy text to clipboard

function copy() {
  var copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

document.querySelector("#copy").addEventListener("click", copy);
Posted by: Guest on September-17-2019
5

how to copy text in the clipboard in js

<html>
  <input type="text" value="Hello world"(Can be of your choice) id="myInput"(id is the name of the text, you can change it later)
<button onclick="Hello()">Copy Text</button>

<script>
  function Hello() {
  var copyText = document.getElementById('myInput')
  copyText.select();
  document.execCommand('copy')
  console.log('Copied Text')
}
</script>
Posted by: Guest on October-14-2020
0

copy to clipboard

navigator.clipboard.writeText('Text To Copy');
Posted by: Guest on May-25-2021
0

copy to clipboard

function copyToClipboard(text) {
    var inputc = document.body.appendChild(document.createElement("input"));
    userPreference = "COPIED!";
    inputc.value = window.location.href;
    inputc.focus();
    inputc.select();
    document.execCommand('copy');
    inputc.parentNode.removeChild(inputc);
    document.getElementById("msg").innerHTML = userPreference;

    setTimeout(function(){
    document.getElementById("msg").innerHTML = '';
    }, 2000);
}

/* HTML */
/* call "onclick="copyToClipboard()" */
<button onclick="copyToClipboard()" class="copy-url-btn">Copy link to page</button>
Posted by: Guest on September-07-2021
0

Copy to Clipboard

const copyToClipboard = (text) => navigator.clipboard.writeText(text);

copyToClipboard("Hello World");
Posted by: Guest on September-28-2021

Browse Popular Code Answers by Language