You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
but anyhow, these code doesn't work for me and always have an error said: Undefined function Client().
Additionally to that, I tried remove .Client(), then clip.glue(); is undefined.
So far, this is what I got:
<!DOCTYPE html><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type" content="text/html; charset=UTF-8" />
<scripttype="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.6/ZeroClipboard.js"></script><linkhref="embedCode.css" rel="stylesheet" type="text/css" />
</head><body><divclass="copyAllContent" id="copyAll"><divid="copy1">
content1
</div><buttonclass="copySectionBtn" id="button1"></button><divid="copy2">
content2
</div><buttonclass="copySectionBtn" id="button2"></button></div><buttonclass="copyAllBtn" id="copyAll"></button></body><scripttype="text/javascript">ZeroClipboard.config({zIndex: 1000100002});//For other future purpose, I have to make this//should copy content1 and content2 after click this button//This button right now copy content2varclientAll=newZeroClipboard(document.getElementById('copyAll'));varcopyAll=copy1+copy2;clientAll.setText(copyAll);console.log("I got all");//should ONLY copy content1//This button right now copy content2varclient1=newZeroClipboard(document.getElementById('button1'));varcopy1=document.getElementById("copy1").innerText;client1.setText(copy1);console.log("I got: "+copy1);//should ONLY copy content2//This button right now works fine.varclient2=newZeroClipboard(document.getElementById('button2'));varcopy2=document.getElementById("copy2").innerText;client2.setText(copy2);console.log("I got 2");</script></html>
In this case, I would like to use 3 buttons to copy 3 different content to clipboard, but the code above makes all my buttons copy only content2, which means only client2 is working.
Please do not provide me any jQuery solutions as I know nothing about that...
If my question is duplicated, please advise me the link (no jQuery please) that I may missed in past week.
I appreciate all comments and helps!
PS: My English is not that good as second language, so if there has anything unclear, please make comments for me, I will correct it.
The text was updated successfully, but these errors were encountered:
ZeroClipboard.Client and client#glue are long-gone API methods. Please consult our docs here on GitHub for the latest and correct API (and other) documentation.
These documents will also talk at length about the multiple available mechanisms for copying data with ZeroClipboard, as well as some gotchas to watch out for (like the fact that setText, which you are using, puts data into a temporary store that is cleared out after every clipboard injection).
Here's a suggested update for your HTML:
<!DOCTYPE html><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type" content="text/html; charset=UTF-8" />
<scripttype="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.6/ZeroClipboard.js"></script><linkhref="embedCode.css" rel="stylesheet" type="text/css" />
</head><body><divclass="copyAllContent"><divid="copy1">
content1
</div><buttonclass="copySectionBtn" id="button1" data-clipboard-target="copy1"></button><divid="copy2">
content2
</div><buttonclass="copySectionBtn" id="button2" data-clipboard-target="copy2"></button></div><buttonclass="copyAllBtn" id="copyAll"></button><scripttype="text/javascript">ZeroClipboard.config({zIndex: 1000100002});//For other future purpose, I have to make thisvarcopyBtn1=document.getElementById("button1");varcopyBtn2=document.getElementById("button2");varcopyBtnAll=document.getElementById("copyAll");varclient=newZeroClipboard([copyBtn1,copyBtn2,copyBtnAll]);// Release DOM referencescopyBtn1=copyBtn2=copyBtnAll=null;client.on("error",function(event){console.error("ERROR!\n"+JSON.stringify(event,null,2));});client.on("ready",function(event){console.log("Ready!");client.on("copy",function(event){console.log("Copying...");if(event.target.id==="copyAll"){varcopy1=document.getElementById("copy1");varcopy2=document.getElementById("copy2");vartextToCopy="";if(copy1){textToCopy+=copy1.value||copy1.textContent||copy1.innerText;}if(copy2){textToCopy+=(textToCopy ? "\n" : "");textToCopy+=copy2.value||copy2.textContent||copy2.innerText;}if(textToCopy){console.log("Text to copy:\n"+textToCopy);event.clipboardData.clearData();event.clipboardData.setData("text/plain",textToCopy);}// Release DOM referencescopy1=copy2=null;}elseif(event.relatedTarget){// If you ONLY want the "text/plain" format to end up in your clipboard for `button1` and// `button2`, remove the default HTML text being populatedevent.clipboardData.clearData("text/html");}});});</script></body></html>
@dukesmike: For our own improvement opportunities, can you tell me how it is that you happened upon documentation/tutorials that suggested you use long-removed API methods like ZeroClipboard.Client and client#glue? That might be helpful for us to track down or encourage blog authors to publish an updated tutorial, etc. Please let us know. Thanks!
I have been struggling on this for several days, and read several threads, most of them were saying use some code like:
but anyhow, these code doesn't work for me and always have an error said: Undefined function Client().
Additionally to that, I tried remove .Client(), then clip.glue(); is undefined.
So far, this is what I got:
In this case, I would like to use 3 buttons to copy 3 different content to clipboard, but the code above makes all my buttons copy only content2, which means only client2 is working.
Please do not provide me any jQuery solutions as I know nothing about that...
If my question is duplicated, please advise me the link (no jQuery please) that I may missed in past week.
I appreciate all comments and helps!
PS: My English is not that good as second language, so if there has anything unclear, please make comments for me, I will correct it.
The text was updated successfully, but these errors were encountered: