0

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.

virsir
  • 14,359
  • 23
  • 71
  • 108
  • I'm assuming you would like to copy the html inside the table. You would need to build some kind of select tool very much like chrome's web inspector. And then you should be able to copy the inner html of whatever element you choose. I have done this before. If you need more help please provide what you have tried and more details. – ama2 Oct 10 '12 at 02:36

2 Answers2

1

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.

Community
  • 1
  • 1
davehale23
  • 4,322
  • 2
  • 24
  • 39
0

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.

jiguang
  • 222
  • 1
  • 2
  • 7