Home > Web Front-end > JS Tutorial > Clipboard.js JavaScript copy-paste library without Flash_javascript tips

Clipboard.js JavaScript copy-paste library without Flash_javascript tips

WBOY
Release: 2016-05-16 15:37:33
Original
1474 people have browsed it

clipboard.js implements the function of copying browser content to the system clipboard in pure JavaScript (no Flash). Can be used in browser and Node environments. Support Chrome 42, Firefox 41, IE 9, Opera 29

Official website: https://github.com/zenorocha/clipboard.js

Software download: http://www.jb51.net/jiaoben/385604.html

Official usage: https://zenorocha.github.io/clipboard.js/#example-text

Sample code:

Official example one:
Online demo: http://demo.jb51.net/js/2015/clipboard/

<script src="clipboard.min.js"></script>
 <textarea id="bar" cols="62" rows="5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">脚本之家是国内专业的网站建设资源、脚本编程学习类网站,提供asp、php、asp.net、javascript、jquery、vbscript、dos批处理、网页制作、网络编程、网站建设等编程资料。</textarea>

<!-- Trigger -->
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#bar">
  Cut to clipboard
</button>
<script>
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
  console.info('Action:', e.action);
  console.info('Text:', e.text);
  console.info('Trigger:', e.trigger);
alert("复制成功");
  e.clearSelection();
});

clipboard.on('error', function(e) {
  console.error('Action:', e.action);
  console.error('Trigger:', e.trigger);
});
</script>
Copy after login

Official example two:

<script src="dist/clipboard.min.js"></script>
<button class="btn">
<script type="text/javascript">
var clipboard = new Clipboard('.btn');

clipboard.on('success', function(e) {
  console.info('Action:', e.action);
  console.info('Text:', e.text);
  console.info('Trigger:', e.trigger);

  e.clearSelection();
});

clipboard.on('error', function(e) {
  console.error('Action:', e.action);
  console.error('Trigger:', e.trigger);
});
</script>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template