I have write javascript to select the table but I want to now automaticaly copy it after the click of the button.Please help me.My javascript is like this.
f
function selectElementContents(el) {
var body = document.body, range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
sel = window.getSelection();
sel.removeAllRanges();
try {
range.selectNodeContents(el);
sel.addRange(range);
} catch (e) {
range.selectNode(el);
sel.addRange(range);
}
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
}
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");}
by using clicpboard.js
making it much easier.
for more info, check: https://webdesign.tutsplus.com/tutorials/copy-to-clipboard-made-easy-with-clipboardjs--cms-25086
<script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.4.0/clipboard.min.js">
(function(){
new Clipboard('#copy-table-button');
})();
</script>
<button class="btn" id="copy-table-button" data-clipboard-target="#table_results">Copy</button>
<table id='table_results' >
</table>