Answers for "clipboard api javascript"

11

copy to clipboard javascript

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
2

javascript copy to clipboard

function copyToClipboard(text) {
  var input = document.body.appendChild(document.createElement("input"));
  input.value = text;
  input.focus();
  input.select();
  document.execCommand('copy');
  input.parentNode.removeChild(input);
}
Posted by: Guest on May-20-2020
0

javascript get clipboard contents

#note that this will prompt the user to allow acces to clipboard
navigator.clipboard.readText().then(text => {
    console.log('Clipboard content is: ', text);
  })
  .catch(err => {
    console.error('Failed to read clipboard contents: ', err);
});
Posted by: Guest on October-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language