Answers for "copy something to clipboard javascript"

26

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
3

javascript copy to clipboard

<head><script>
function copyToCliBoard() {
  var copyText = document.getElementById("myInput");
  copyText.select();
  copyText.setSelectionRange(0, 99999); /* For mobile devices */
  document.execCommand("copy");
  alert("Copied the text: " + copyText.value);
}
</script></head>

<body>
<input type="text" value="Hello World" id="myInput">
<button onclick="copyToCliBoard()">Copy text</button>
</body>
Posted by: Guest on March-15-2021
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
4

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 javascript dom

navigator.clipboard.writeText('Text');
Posted by: Guest on February-02-2021
2

js copy string to clipboard

const el = document.createElement('textarea');
el.value = str;	//str is your string to copy
document.body.appendChild(el);
el.select();
document.execCommand('copy');	// Copy command
document.body.removeChild(el);
Posted by: Guest on August-22-2020

Code answers related to "copy something to clipboard javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language