Copy Table Rows To Clipboard- Copying Only The First Page
I am using this reference to copy my table(paginated) to clipboard- Select a complete table with Javascript (to be copied to clipboard) But the problem I am facing here is, it is j
Solution 1:
It can be done by JavaScript only.
It can be done in two step:
Step 1 : Select table get using selection command
Step 2 : Apply clipboard using
document.execCommand("copy");
Please check below :
functionselectElementContents(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);
}
document.execCommand("copy");
} elseif (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
range.execCommand("Copy");
}
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><tableid="tableId"><thead><tr><th>Heading 1</th><th>Heading 2</th></tr></thead><tbody><tr><td>cell 1</td><td>cell 2</td></tr><tr><td>cell 3</td><td>cell 4</td></tr></tbody></table><inputtype="button"value="select table"onclick="selectElementContents( document.getElementById('tableId') );">
Now Ctrl+V
paste clipboard value as per your requirement
Post a Comment for "Copy Table Rows To Clipboard- Copying Only The First Page"