Click to See Complete Forum and Search --> : IE: successive copy-to-clipboards failing


molesquirrel
12-09-2003, 01:08 AM
Hey! Just found this forum, so I thought I'd give it a shot...

So...I have a page that has 3 or 4 bits of text stored in div's, and each has a button associated with it. If you push that button, you can (IE users) copy that text to the clipboard via this method:

function copyExport(type)
{
window.clipboardData.setData("Text", document.getElementById('export_'+type).innerText);
}

where, of course, export_(type) is where the text is.

Now...using IE 6.02, suppose I have 4 pieces of data, and 4 buttons. If I click on each one of those, the data is successfully copied to the clipboard.

However, I'd like to add a fifth button that will copy all that data to the clipboard in successive bursts

Something to the extent of

onClick="copyExport('a'); copyExport('b'); copyExport('c'); copyExport('d');"

[note: the data can't all be sent at once; it must be copied in individual pieces]

The problem is that it never seems to 'copy' all 4 pieces. Only one or two random ones seem to appear in the clipboard at any point.

I tried sticking an alert() in the method so there was a pause between each copy command, and that seemed to do the trick, but of course I'd rather not have the user subjected to that. I tried using setTimeout to put a 100ms delay in between each copy command, but that didn't seem to work.

Any ideas as to why this is happening, and how to fix it?

Thanks in advance.

skriptor
12-09-2003, 03:20 AM
Hi,
maybe I'm wrong, but in my opinion clipboard only can hold one piece of information. So after your onclick clipboard always contains information from div d.

Good luck, skriptor

Pittimann
12-09-2003, 03:41 AM
Hi!

I think the same as skriptor, but that doesn't mean of course, that you cannot get what you want. Example:

<script language="JavaScript" type="text/javascript">
<!--
window.clipboardData.setData("Text", "");//clear clipboard
var alreadyThere="";
var separator="";
function copyExport(type) {
alreadyThere=window.clipboardData.getData("Text");
if (alreadyThere!="") separator="<br>";
window.clipboardData.setData("Text",alreadyThere+separator+ document.getElementById('export_'+type).innerText);
}
//-->
</script>

For your 5th button add another function being called onclick button 5 containing something like:

window.clipboardData.setData("Text",document.getElementById('export_'+a).innerText+document.getElementById('export_'+b).innerText+docum ent.getElementById('export_'+c).innerText+document.getElementById('export_'+d).innerText);

(can be done in a loop as well)...

Cheers - Pit

molesquirrel
12-09-2003, 10:42 AM
ah, sorry! I guess I was a bit vague in a few places...

I agree with the clipboard only being able to hold one 'piece of info'.

In a nutshell, the people that are going to be viewing this site have a third party piece of software running in the background which monitors the clipboard. Any time it sees one of these 'export' packets, it processes it's information, etc, etc.

So..it can't process all 4 at once, but it can process them incrementally. That's why I only need one piece of data in the clipboard at a time and why I can't just string concat the 4 pieces of data = /.

Thanks for your help, though!