Storyline Screen Shot

Storyline 360: Copy slide text with JavaScript

Storyline

I needed students to be able to copy text out of Storyline for a project I’m working on. After a quick search of the Articulate forums, I was directed to this page: POP99; – Copy text to clipboard. There wasn’t much available in terms of instructions, and for my use case, I needed multiple variables tied together with some static text. I fiddled around with the Javascript code and got everything working perfectly! Javascript may look a little intimidating if you haven’t done much coding before. Don’t be scared! The code is shared below, and I have broken the process down for you in a video as well.

Enjoy!

var player = GetPlayer();
var Var1 = player.GetVar("Variable1");
var Var2 = player.GetVar("Variable2");
var Var3 = player.GetVar("Variable3");
copyFunction ("Static text goes here " + Var1 + " don't forget to account for spaces " + Var2 + " and punctuation " + Var3 + ".");

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!");
}

Share your love
Default image
Crystal Klarich

2 Comments

  1. Heather Caprette
    Heather Caprette

    Hi Crystal,

    Thank you for sharing this code. I’m trying to copy three variables to the clipboard in a Storyline360 project, much like you’ve done here. I noticed in the YouTube video there appeared to be more spaces in the code. That is spaces before and after the + symbols and = symbols. But, above, the spaces seem taken out. Do you know if it matters to JavaScript if there are spaces before and after the + or = ?
    Thank you.
    Heather Caprette

    • Hi Heather!

      When coding, any spaces that are outside of the quotation marks don’t count. Formatting/spacing is generally forgiving when coding so that something like a double space or missed space doesn’t usually break everything. Quotation marks signal your text entry, so within the quotation marks, your spacing does matter. If you look at the code snippet here:

      (“Static text goes here ” + Var1 + “ don’t forget to account for spaces ” + Var2 + “ and punctuation ” + Var3 + “.“)

      – you will see that my spaces are after and before the text within the quotation marks. You could have “Text”+” text.” or “Text ” + “text.” and both would still show as “Text text.” in your output.

      The equal sign is the same way – you don’t need spaces before and after the equal sign, but the name of your variable inside the quotation marks must match your Storyline variable exactly.

      Hopefully this helps 🙂

Comments are closed.