/    Sign up×
Community /Pin to ProfileBookmark

IE: successive copy-to-clipboards failing

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.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@skriptorDec 09.2003 — 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
Copy linkTweet thisAlerts:
@PittimannDec 09.2003 — Hi!

I think the same as skriptor, but that doesn't mean of course, that you cannot get what you want. Example:
<i>
</i>&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
window.clipboardData.setData("Text", "");//clear clipboard
var alreadyThere="";
var separator="";
function copyExport(type) {
alreadyThere=window.clipboardData.getData("Text");
if (alreadyThere!="") separator="&lt;br&gt;";
window.clipboardData.setData("Text",alreadyThere+separator+ document.getElementById('export_'+type).innerText);
}
//--&gt;
&lt;/script&gt;

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+document.getElementById('export_'+c).innerText+document.getElementById('export_'+d).innerText);

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

Cheers - Pit
Copy linkTweet thisAlerts:
@molesquirrelauthorDec 09.2003 — 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!
×

Success!

Help @molesquirrel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...