Reputation: 15499
For example, I have a table dom in page, how do I select/highlight it by javascript, in IE and Firefox browser.
I just want to copy the table dom into clipboard when user use ctrl+c to copy something.
Upvotes: 0
Views: 152
Reputation: 4372
Here is a pretty simple example:
<table id="someTable">
<tr>
<td>ajlaksjd flsajlsd</td>
</tr>
</table>
<script>
window.prompt ("Copy to clipboard: Ctrl+C, Enter",
document.getElementById("someTable").outerHTML);
</script>
I like this because you get the whole table and you don't have to worry about the security concerns that arise when you start messing with a user's copy/paste buffer automatically. For a good discussion about many options you might have about the auto copy/paste, check out this post.
Upvotes: 1
Reputation: 362
You can use JS wrapping the selected/highlighted element, the wrapper should has some visual effects, such as border or outline, then you can use el.innerHTML
to get the dom, at last, use some library like zeroclipboard to copy to your clipboard.
Upvotes: 0