首頁 > web前端 > js教程 > 主體

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

php中世界最好的语言
發布: 2018-03-19 16:25:00
原創
3184 人瀏覽過

這次帶給大家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中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!