By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

clip board data as html

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.