Answers for "copy function in javascript"

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
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
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
2

javascript copy to clipboard

$(document).ready(function(){
	$("#ewefmwefmp").click(function(){
    //alert()
      var copyText = document.getElementById("myInput");
      copyText.select();
      copyText.setSelectionRange(0, 99999)
      document.execCommand("copy");
      alert("Copied the text: " + copyText.value);
    
    });
});
Posted by: Guest on September-09-2020
0

javascript copy to clipboard

const copyToClipboard = () => {

  navigator.permissions.query({name: "clipboard-write"}).then(result => {
    if (result.state == "granted" || result.state == "prompt") {
      // write to the clipboard now
      updateClipboard('I copy this string');
    }
  });
};

const updateClipboard = (newClip) => {
  
  navigator.clipboard.writeText(newClip).then(() => {
    // clipboard successfully set
	console.log('success');
  }, () => {
    // clipboard write failed
    console.log('Failed to copy');
  });
};

const btn = document.getElementById('copy-button');

btn.addEventListener('click', copyHashtagToClipboard);
Posted by: Guest on February-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language