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'.")
}
}