Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting whole table/text for copying to clipboard

I have a htlm table with lots of data the user might want to copy to paste into Excel or whatever...

Since it's big I want to help user selecting it, he can then copy & paste himself.

I found this Select a complete table with Javascript (to be copied to clipboard)

but it creates a security error (code 1000) in FF, any thoughts? Can this be done more efficiently with jQuery?

like image 884
David Thorisson Avatar asked Oct 26 '22 19:10

David Thorisson


1 Answers

I've never used it, but there is a jQuery clipboard plugin that could suit your needs. It sounds like it would copy something to the clipboard, but should work cross-browser. The code would be something like

$.clipboard($('#tableContainer').html()); 

Edit: I just noticed that this solution would require non-IE browsers to have Flash installed, which is inconvenient as best and makes it unusable at worst. The only way I could think to do this without having the browser access the clip board would be to display a hidden textarea control with the results of this call:

$('#tableContainer').html()

and then allow the user to select all the text and copy it. It would work, but not be as elegant as the plugin solution.

like image 175
rosscj2533 Avatar answered Nov 15 '22 05:11

rosscj2533