Copy Text to Clipboard
JSsnippets

Copy Text to Clipboard

function copyToClipboard() {

  const copyText = document.getElementById("myInput");
  copyText.select();
  document.execCommand("copy");
  
}

//new API
function copyToClipboard(){

navigator.clipboard.writeText(document.querySelector('#myInput').value).then(function() {
  /* clipboard successfully set */
}, function() {
  /* clipboard write failed */
});
}

In the meantime, if you have any JavaScript questions, feel free to contact me. I'll do by best to create free articles to answer your questions.

Please follow me on LinkedIn / Twitter / Facebook / Codesandbox / Codepen.

要查看或添加评论,请登录

Dan Ichim的更多文章

社区洞察

其他会员也浏览了