Answers for "how to use copy to clipboard"

11

copy link 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
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

Code answers related to "Javascript"

Browse Popular Code Answers by Language