473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

clip board data as html

hi all,

I am trying to copy the contents of a div to the clip board the same
way that Microsoft copies it when you select the contents with the
mouse and select copy. However, something is not the same.

here is the code simplified:
var s = document.getElementById("testDiv").innerHTML;
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("text", s);
}

If I use this method to copy to clipboard, then to Word, i get:
<TABLE><TBODY><TR><TD>text</TD></TR></TBODY></TABLE>

however, if I select the table with the mouse, select copy, and paste
in to word, the actual table shows up like it did in the web page.

Any way to make the clipboard put the html in the correct format that
word wants?

Thanks,
-Scott
Jun 27 '08 #1
4 7310
SirCodesALot wrote on 30 mei 2008 in comp.lang.javascript:
hi all,

I am trying to copy the contents of a div to the clip board the same
way that Microsoft copies it when you select the contents with the
mouse and select copy. However, something is not the same.

here is the code simplified:
var s = document.getElementById("testDiv").innerHTML;
Try IE only:

var s = document.getElementById("testDiv").innerText
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("text", s);
}

If I use this method to copy to clipboard, then to Word, i get:
<TABLE><TBODY><TR><TD>text</TD></TR></TBODY></TABLE>

however, if I select the table with the mouse, select copy, and paste
in to word, the actual table shows up like it did in the web page.

Any way to make the clipboard put the html in the correct format that
word wants?

Thanks,
-Scott


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2
On May 30, 2:32*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
SirCodesALot wrote on 30 mei 2008 in comp.lang.javascript:
hi all,
I am trying to copy the contents of a div to the clip board the same
way that Microsoft copies it when you select the contents with the
mouse and select copy. *However, something is not the same.
here is the code simplified:
var s = document.getElementById("testDiv").innerHTML;

Try IE only:

var s = document.getElementById("testDiv").innerText


if( window.clipboardData && clipboardData.setData )
* * *{
* * * * * clipboardData.setData("text", s);
* * }
If I use this method to copy to clipboard, then to Word, i get:
<TABLE><TBODY><TR><TD>text</TD></TR></TBODY></TABLE>
however, if I select the table with the mouse, select copy, and paste
in to word, the actual table shows up like it did in the web page.
Any way to make the clipboard put the html in the correct format that
word wants?
Thanks,
-Scott

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)- Hide quoted text -

- Show quoted text -
thanks for your reply, that does work, but it drops all the formating
for the tabels. When you selected with content with the mouse and do a
copy, MS must be saving other information about the formating for the
table.
Jun 27 '08 #3
On May 30, 4:11*pm, SirCodesALot <sjour...@gmail.comwrote:
On May 30, 2:32*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:


SirCodesALot wrote on 30 mei 2008 in comp.lang.javascript:
hi all,
I am trying to copy the contents of a div to the clip board the same
way that Microsoft copies it when you select the contents with the
mouse and select copy. *However, something is not the same.
here is the code simplified:
var s = document.getElementById("testDiv").innerHTML;
Try IE only:
var s = document.getElementById("testDiv").innerText
if( window.clipboardData && clipboardData.setData )
* * *{
* * * * * clipboardData.setData("text", s);
* * }
If I use this method to copy to clipboard, then to Word, i get:
<TABLE><TBODY><TR><TD>text</TD></TR></TBODY></TABLE>
however, if I select the table with the mouse, select copy, and paste
in to word, the actual table shows up like it did in the web page.
Any way to make the clipboard put the html in the correct format that
word wants?
Thanks,
-Scott
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)- Hide quoted text -
- Show quoted text -

thanks for your reply, that does work, but it drops all the formating
for the tabels. When you selected with content with the mouse and do a
copy, MS must be saving other information about the formating for the
table.- Hide quoted text -

- Show quoted text -
I found a way to do it in IE:
function copyDivToClipboard(divId) {
var range = document.createRange();
range.selectNode(document.getElementById(divId));
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);

try
{
range.execCommand("Copy");
}
catch (e)
{
alert("Sorry, your browser does not support this feature. Please
right click the highlighted text and select 'copy'.")
}
}
Jun 27 '08 #4
SirCodesALot schrieb am 30.05.2008 23:11:
On May 30, 2:32 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>SirCodesALot wrote on 30 mei 2008 in comp.lang.javascript:
thanks for your reply, that does work, but it drops all the formating
for the tabels. When you selected with content with the mouse and do a
copy, MS must be saving other information about the formating for the
table.
The Clipboard in Windows is capable to host multiple information
simultanously.

Text only+HTML coded version

A Texteditor used the textonly, while Word is able to recognise the HTML
design.

Try in Word "edit/paste special..." to see what is in there.

--
Mit freundlichen Grüßen
Holger Jeromin
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Danny | last post by:
I am creatng a form and using wizard to automate some things. I want the user to be able to Duplicate a record so I set this up behind a command button on the form. THe wizard did all the work. ...
2
by: Ben | last post by:
Hi, I am writing an aspx page which submits data via and e-mail. I want to allow a user to paste and image from the clipboard (screen dump for example) and then this image must either be saved...
1
by: Peter | last post by:
Team .Net, I'm looking for a component or anything that will alow me to take string data formated in HTML and convert it to a pdf. I have browsed throught the compnonet shopper and have not yet...
1
by: Mamatha | last post by:
Hi I have some items in listview. I want to copy the selected items from listview using the clip board mechanism in VB.NET. I used this code but it was not copied. For Each lsvrow As...
2
by: boomcreation | last post by:
Hi, When I load a userControl, I check if I have a variable session. If my variableSession1 = "A" and do nothing. but if my variableSession1 = "B", I want clear the html in my control and...
0
by: atif283 | last post by:
Hi I m working on clip board application in vb.net and i need to paste file on window's desktop how i will do it can any one help me in this regard? Thankz in advance
1
dmjpro
by: dmjpro | last post by:
could anyone tell me how can i access the clip board using JS???? plz help. kind regards. dmjpro.
3
by: atif283 | last post by:
Hi I m worki on clip board m trying to copy RTF data(Text+Image) both txt and image on clip board its only pasting text On Excel not the image can any one help me in this regard I m using your...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.