“Значение копирования JavaScript в буфер обмена” Ответ

Скопируйте текст в буфер обмена JavaScript

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

JavaScript Text в буфер обмена

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

JS копировать текст в буфер обмена

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

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

Скопируйте в буфер обмена Javascript dom

	navigator.clipboard.writeText('Text');

JavaScript How-D-I-Copy-to-Clipboard-In-Javascript

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

Значение копирования JavaScript в буфер обмена

function fallbackCopyTextToClipboard(text) {
  var textArea = document.createElement("textarea");
  textArea.value = text;
  
  // Avoid scrolling to bottom
  textArea.style.top = "0";
  textArea.style.left = "0";
  textArea.style.position = "fixed";

  document.body.appendChild(textArea);
  textArea.focus();
  textArea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Fallback: Copying text command was ' + msg);
  } catch (err) {
    console.error('Fallback: Oops, unable to copy', err);
  }

  document.body.removeChild(textArea);
}
function copyTextToClipboard(text) {
  if (!navigator.clipboard) {
    fallbackCopyTextToClipboard(text);
    return;
  }
  navigator.clipboard.writeText(text).then(function() {
    console.log('Async: Copying to clipboard was successful!');
  }, function(err) {
    console.error('Async: Could not copy text: ', err);
  });
}

var copyBobBtn = document.querySelector('.js-copy-bob-btn'),
  copyJaneBtn = document.querySelector('.js-copy-jane-btn');

copyBobBtn.addEventListener('click', function(event) {
  copyTextToClipboard('Bob');
});


copyJaneBtn.addEventListener('click', function(event) {
  copyTextToClipboard('Jane');
});
Horrible Heron

Ответы похожие на “Значение копирования JavaScript в буфер обмена”

Вопросы похожие на “Значение копирования JavaScript в буфер обмена”

Больше похожих ответов на “Значение копирования JavaScript в буфер обмена” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования