Answers for "javascript "clipboard to text""

56

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
1

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
0

copy to clipboard javascript

$('.copyable').click(function (event) {
  const targetInput  = document.getElementById('copyable');
  targetInput.select();
  document.execCommand('copy');
  //navigator.clipboard.writeText(targetInput.getAttribute('data-url'));
  alert("Link Copied");
});
Posted by: Guest on September-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language