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:
<script src= "Lib/clipboard.js-master/dist/clipboard.min.js" ></script>
First introduce JS package.
- Html
<!--Target-- <input id= "foo" value= "http://www.968309.com/mobile.php" > <!- -Trigger--- class= "Btn" data-clipboard-target= "#foo" > Copy </button>
- 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! ') ) });
- The Red Callout section supports only input and textarea. No other support!
- 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