Forum Discussion
Copy Text Variable to Clipboard
I need some help.
I need users to be able to click a button to copy a text variable to their clipboard, which can then be pasted in a word doc. This doesn't necessarily have to be done through a text variable, but is the only way I've come to think this will work.
In the past I used a text entry field that when published allows users to copy and paste the text by highlighting and right clicking as you normally would. I've been asked to eliminate that route and only use a one-click copy to clipboard button.
I was able to get this to work using JavaScript, however, this only worked in IE and I desperately need it to work in FireFox. I used the method below from another post to get it to work in IE:
I've sifted through post after post and haven't found anything that will work for this situation. If at all possible, this would be great if this worked with HTML5 as well.
Any help would be greatly appreciated. Thanks!
- JacksonHamnerCommunity Member
No problem, I'm glad you got it working :)
Thanks for the continued assistance Jackson :)
- CristinaBermdezCommunity Member
Excellent! I worked for me too!
Thanks for sharing such valuable tips and tricks! :-)Br,
Cristina Glad this thread was able to assist you as well Cristina :)
- ignaciovazquezCommunity Member
Hi I’m trying to use a button to copy a variable directly to the clip board and I have not had much success.
“copytext” is the variable I am using as an input in articulate.
This is the java script I added to the articulate button:
var player = GetPlayer();
var vtext= player.GetVar("copytext");
holdtext.innerText=vtext;
Copied=holdtext.createTextRange();
Copied.execCommand("Copy");And I added this to the story.html file:
<textarea id="holdtext" style="display: none;"></textarea>any thoughts on how I can fix this?
- ChristiePollickCommunity Member
Hi, Ignacio -- Thanks for reaching out, and while JS is not something for which we can offer support, perhaps others here in the community will be able to stop in to share some ideas to assist!
- HollyMacDonaldSuper Hero
I am wondering if it's possible to use javascript to copy supplied text to the clipboard. I have a series of Storyline modules with a workbook that they will be writing in and in the Storyline module I would like to have a button that would copy text from the module (not a text entry or select text function), is this possible?
PS I'm a javascript novice.
- HollyMacDonaldSuper Hero
The text would be the same for everyone. Basically there are six options that they'll be able to put in their "workbook" and I was curious if they could click a button in the module and have that prepared text be put on to their system clipboard so they could use it in their word doc.
- HollyMacDonaldSuper Hero
That's awesome Matthew - thank you!
- HollyMacDonaldSuper Hero
Hi Matthew - I've just tested this and what ends up getting copied onto the clipboard is the javascript:
var player = GetPlayer();
var text= player.GetVar("copytext");
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);not the default text I put in the text variable. Do I need to put that text in the javascript?
If you have any insights, let me know!
- ZsoltOlahSuper Hero
Here's an example on Project99 on how to copy text to the clipboard:
https://www.rabbitoreg.com/examples/p99/#/lessons/NPQ2NG0PlDgwjy_ZLbmw6t0PPaoWFEB6
Just change your variable name.
- HollyMacDonaldSuper Hero
Hi Zsolt - thanks for jumping in - Matthew's solution (above) worked. I was able to put the default text in the variable and then that is what was copied to the clipboard. I do love your Project99!