首頁  >  文章  >  web前端  >  navigator.clipboard瀏覽器怎麼製作原生剪貼簿

navigator.clipboard瀏覽器怎麼製作原生剪貼簿

php中世界最好的语言
php中世界最好的语言原創
2018-03-19 16:25:003185瀏覽

這次帶給大家navigator.clipboard瀏覽器怎麼製作原生剪貼板,navigator.clipboard瀏覽器製作原生剪貼簿的注意事項有哪些,以下就是實戰案例,一起來看一下。

瀏覽器原生剪貼簿navigator.clipboard

寫入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);
  });
});

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

請求跨域解決方法CORS

#react-native flatlist上拉加載onEndReached頻繁觸發怎麼解決

Dom屬性的使用方法

#

以上是navigator.clipboard瀏覽器怎麼製作原生剪貼簿的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn