Click button copy to clipboard using jQuery

前端 未结 21 2390
醉话见心
醉话见心 2020-11-21 23:11

How do I copy the text inside a div to the clipboard? I have a div and need to add a link which will add the text to the clipboard. Is there a solution for this?

         


        
21条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 00:08

    Clipboard-polyfill library is a polyfill for the modern Promise-based asynchronous clipboard API.

    install in CLI:

    npm install clipboard-polyfill 
    

    import as clipboard in JS file

    window.clipboard = require('clipboard-polyfill');
    

    example

    I'm using it in a bundle with require("babel-polyfill"); and tested it on chrome 67. All good for production.

提交回复
热议问题