You can use the clipboardJS, this has no dependencies and does not require Flash technology.
The only problem is the support, according to README Apis are used selection
and document#execCommand
and the browsers they support are:
- Firefox 41+
- Chrome 42+
- Internet Explorer 9+
- Opera 29+
basic:
In this example is copied whatever is defined in the attribute data-text:
new Clipboard('button');
<script src="https://raw.githubusercontent.com/zenorocha/clipboard.js/master/dist/clipboard.min.js"></script>
<button data-text='The quick brown fox jumps over the lazy dog.'>
copiar
</button>
copying text from another element:
In this example, whatever is written in the input text.
new Clipboard('button');
<script src="https://raw.githubusercontent.com/zenorocha/clipboard.js/master/dist/clipboard.min.js"></script>
<input id='id-do-input' type='text' placeholder='Texto que será copiado...'/>
<button data-target='id-do-input'>copiar</button>
events:
You can get success or failure information by trying to copy something to the clipboard. Enable the console (Ctrlshiftk) to view the output when you click on the snippet next:
var clip = new Clipboard('button');
clip.on('success', function(e) {
console.info('Ação:', e.action);
console.info('Conteúdo copiado:', e.text);
console.info('Trigger:', e.trigger); // no caso de "copiar de outro elemento"
e.clearSelection();
});
clip.on('error', function(e) {
console.error('Ação:', e.action);
console.error('Trigger:', e.trigger);
});
<script src="https://raw.githubusercontent.com/zenorocha/clipboard.js/master/dist/clipboard.min.js"></script>
<button data-text='Testando eventos'>copiar</button>
I know you have how to do this in Google Chrome, Firefox and Internet Explorer (think) that only with flash.
– Renan Gomes
Because and, today I have implemented with Flash.. only that this showing this message on Google Chrome and I want to prevent.
– Jefferson Alison
See if this helps https://www.npmjs.com/package/clipboard-js
– Wallace Maxters