Use Clipboard.js to make one copy on the phone, paste anywhere

Source: Internet
Author: User

Clipboard.js provides developers with a versatile, lightweight JavaScript library that integrates a practical API, independent of Flash.

    • Clipboard.js Official website: https://clipboardjs.com/
    • Clipboard.js Download (Zip mode): Https://github.com/zenorocha/clipboard.js/archive/master.zip
    • Clipboard.js How to use:
  1. <script src= "Lib/clipboard.js-master/dist/clipboard.min.js" ></script>

    First introduce JS package.

  2. Html
        <!--Target--    <input id= "foo"  value= "http://www.968309.com/mobile.php" >    <!- -Trigger---    class= "Btn" data-clipboard-target= "#foo" > Copy </button>

  3. Js
    // Init    New Clipboard ('. btn ');     // Graceful downgrade: Safari version number >=10, prompted to copy success, otherwise prompted to manually select "copy" to copy    after the text is selected Clipboard.on (' success ', function (e) {        alert (' copy succeeded! ') )        e.clearselection ();    });    Clipboard.on (' error ', function (e) {        alert (' Please select ' copy ' to copy! ') )    });

    • Note the point:
    1. The Red Callout section supports only input and textarea. No other support!
    2. Safari version is more than 10, can be copied directly, if the version is less than 10, you can prompt the user to copy manually by the following code:

Use Clipboard.js to make one copy on the phone, paste anywhere

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.