写入 navigator.clipboard.writeText

navigator.clipboard.writeText('Linr Text to be copied')
  .then(() => {
    console.log('Text copied to clipboard');
  })
  .catch(err => {
    // This can happen if the user denies clipboard permissions:
    console.error('Could not copy text: ', err);
});

读取 navigator.clipboard.readText

navigator.clipboard.readText()
  .then(text => {
    console.log('Pasted content: ', text);
  })
  .catch(err => {
    console.error('Failed to read clipboard contents: ', err);
  });
document.addEventListener('paste', event => {
  event.preventDefault();
  navigator.clipboard.getText().then(text => {
    console.log('Pasted text: ', text);
  });
});

原文:https://developers.google.com/web/updates/2018/03/clipboardapi

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2021-09-28
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-10-15
相关资源
相似解决方案