Issue
Is it possible to select the text (i.e. have it highlighted so that it can be copy+pasted) of every cell in one vertical column of an HTML table.
Is there a JavaScript method, or perhaps an equivalent in some browsers to the Alt-Click-Drag shortcut used in many text editors?
Or is this impossible?
Solution
What you're looking for is called Range
object (TextRange
in IE).
Update: Here's a working code to do what you're suggesting: http://jsfiddle.net/4BwGG/3/
While capturing cell contents, you can format them in any manner you wish. I'm simply appending a new line every time.
Note:
- Works fine in FF 3 and above
- IE (before 9) and Chrome do not support multiple selection.
- Chrome doesn't highlight all cells (but captures all content). Same goes for IE9
- IE 7 & 8 will throw an error.
An alternative is apply a CSS style that simulates highlighting on click of column header and loop through all cells to capture their content. Look and feel of this approach may differ from native selection's look (unless you somehow capture select event and alter the appearnce).
Then use jQuery copy plugin to copy them to clipboard.
Answered By - Mrchief
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.