“Salin ke Clipboard JavaScript” Kode Jawaban

Salin teks ke clipboard javascript

//As simple as this
navigator.clipboard.writeText("Hello World");
Silly Sable

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

Salin nilai tombol ke fungsi clipboard javascript

//U need to have a button with the id the same as its name because it is going to be sent to the clipborad.
/*Like this: */
<button onClick="SelfCopy(this.id)"  id="1">1</button>
<button onClick="SelfCopy(this.id)"  id="2">2</button>
<button onClick="SelfCopy(this.id)"  id="3">3</button>

function SelfCopy(copyText)
  {
      navigator.clipboard.writeText(copyText);
      alert("You just copied this: (" + copyText + ").");
  }
Different Dog

Salin ke Clipboard JavaScript

function copy() {
  var copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

document.querySelector("#copy").addEventListener("click", copy);
Bald Eagle

Salin ke Clipboard JavaScript

navigator.clipboard
  .writeText("Text")
  .then(() => console.log("Copied to clipboard"))
  .catch((err) => console.log(err))
ashirbad-panigrahi

Salin ke 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");
});
Wandering Worm

Jawaban yang mirip dengan “Salin ke Clipboard JavaScript”

Pertanyaan yang mirip dengan “Salin ke Clipboard JavaScript”

Lebih banyak jawaban terkait untuk “Salin ke Clipboard JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya