...

View Full Version : copy rendered table HTML to Clipboard, not Text



mrgr8avill
06-29-2009, 11:40 AM
Hello, and thank you for taking the time to read this.

I have an issue where I am trying to allow the user to click on a table and automatically copy a table into the clipboard. I do this with text using IE:

function clickCopyText(fi) {
window.clipboardData.setData("Text",fi.innerText);
}

so to copy the table, I tried:
function clickCopyHTML(fi) {
window.clipboardData.setData("Text",fi.innerHTML);
}


The Trouble with Tables is the HTML itself gets copied as opposed to the rendered table. I am probably looking at some other way of getting the code to the clipboard, but I am stymied. I can do it with images, but not with rendered HTML.

Any help or information would be greatly appreciated. Thanks again for taking the time to read.

A1ien51
06-29-2009, 12:12 PM
You probably could have found this solution searching for innerText Firefox on your favorite search engine:


var text = "";
if(elem.textContent){
text = fi.textContent;
}
else{
text = fi.innerText;
}

Eric

mrgr8avill
06-29-2009, 12:18 PM
Eric,

Isn't that code for getting the equivalent of innerText in Firefox? Does that transfer rendered HTML to the clipboard using IE? I can't seem to make it work.

Thanks for your reply.

12 Pack Mack
06-29-2009, 01:46 PM
I'm not certain about this, but I believe it works in IE:


var ctrlRange = document.body.createControlRange();
ctrlRange.add(document.getElementById('tableId'));
ctrlRange.execCommand("Copy");

Change 'tableId' to the actual ID of the table:


<table id='myTable'>

mrgr8avill
06-29-2009, 03:08 PM
Didn't work on IE7, but it got me going in the right direction. What ended up working was:

var div = document.getElementById('divID');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';

THANKS!!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum