“JavaScript mendapatkan konten clipboard” Kode Jawaban

Teks JavaScript ke 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);
}
Dennis "Awesome" Rosenbaum

JavaScript mendapatkan konten clipboard

#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);
});
Friendly Hawk

Salin JavaScript ke 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);
}
TC5550

Salin JavaScript ke 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);
    
    });
});
A D Bhowmick

Salin JavaScript ke clipboard

var copyTextarea = document.getElementById("someTextAreaToCopy");
copyTextarea.select(); //select the text area
document.execCommand("copy"); //copy to clipboard
Grepper

js mendapatkan teks yang disalin

navigator.permissions.query({name: "clipboard-write"}).then(result => {
  if (result.state == "granted" || result.state == "prompt") {
    /* write to the clipboard now */
  }
});
Modern Mouse

Jawaban yang mirip dengan “JavaScript mendapatkan konten clipboard”

Pertanyaan yang mirip dengan “JavaScript mendapatkan konten clipboard”

Lebih banyak jawaban terkait untuk “JavaScript mendapatkan konten clipboard” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya