1// Since Async Clipboard API is not supported for all browser!
2function copyTextToClipboard(text) {
3 var textArea = document.createElement("textarea");
4 textArea.value = text
5 document.body.appendChild(textArea);
6 textArea.focus();
7 textArea.select();
8
9 try {
10 var successful = document.execCommand('copy');
11 var msg = successful ? 'successful' : 'unsuccessful';
12 console.log('Copying text command was ' + msg);
13 } catch (err) {
14 console.log('Oops, unable to copy');
15 }
16
17 document.body.removeChild(textArea);
18}
1function copyToClipboard(text) {
2 var input = document.body.appendChild(document.createElement("input"));
3 input.value = text;
4 input.focus();
5 input.select();
6 document.execCommand('copy');
7 input.parentNode.removeChild(input);
8}