Forum Discussion

MichelleSchr546's avatar
MichelleSchr546
Community Member
3 years ago

Copy Text from Course to Clipboard

Hello! I'm trying to allow the learner to click a button which will copy a URL to their clipboard. Which in turn will allow them to paste it into a word document or a web browser. I have the JavaScript set up and it works great.

Here's the script I'm using:

var player = GetPlayer();
var text = player.GetVar("MyTextVariable");
copyFunction (text);

function copyFunction(tt) {

const copyText = tt;
const textArea = document.createElement('textarea');
textArea.textContent = copyText;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
alert("Copied to clipboard!");
}

 

I have changed the MyTextVariable to the name of my variable in SL.

I have changed (text) to the URL that should be copied.

But when I reuse that script and change the variable and URL on a different slide both slides copy the new URL instead of the one in the script. What am I doing wrong?

Thanks.

  • Hey Michelle,

    Did you manage to get this fixed? 

    I'm very familiar with both JavaScript and Storyline, so if you paste the scripts that you have on both slides here, I'll do my best to help you out :)