[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy table to clipboard

Posted on 2004-11-04
4
Medium Priority
?
2,705 Views
Last Modified: 2008-01-09
Hi all,

I have a page with html table in it.

I want to add a button that will select and copy the table to the clipboard,

How can I do that?
0
Comment
Question by:kobi_ab
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
eyeh8u earned 500 total points
ID: 12493913
This will work in IE:
window.clipboardData.setData("Text", document.all['tableid'].innerHTML);

ASsuming you want to copy the HTML of the table. To include the table tag I would do:

<div id="tableid">
<table>...</table>
</div>

Then the <table>...</table> part will be copied to the clipboard.

To be cross-browser, you need to look at something like this: http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20233392.html and combine the two techniques.
0
 

Author Comment

by:kobi_ab
ID: 12493996
Hi eyeh8u and all

I want to paste the table in Excel, so i need the data in a table format and not the html
0
 
LVL 5

Expert Comment

by:eyeh8u
ID: 12494060
Today, Microsoft are smiling on you.

<table>
<tr>
<td>blah</td><td>blah</td></tr>
<tr><td>blah</td><td>blah</td></tr>
</table>

Select that text (with your mouse cursor, manualy, no javascript magic for you here)

And paste it into a new Excel spreadsheet. Excel natively understands HTML and imports that into four clean cells in the document.

SO the javascript would allow you to select the table into your clipboard automagicaly, then you will have the <table>..</table> in your clipboard, paste it into Excel and bob is your mother's brother.
0
 

Author Comment

by:kobi_ab
ID: 12494172
Thanks alot eyeh8u

It works perfectly

By the way my mother's brother name is not Bob :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question