Forum Discussion
JavaScript in Storyline and RISE
Nick, there are three basic functions used to have Storyline and JavaScript communicate back and forth:
var player = GetPlayer(); ... opens communication between JavaScript and an instance of Storyline. You can change "player" after "var" to any variable name you would like to use (e.g., "var storyline" or whatever). However, you cannot change "Player" in "GetPlayer()". "Player" just refers to an instance of a published Storyline project. You must include the GetPlayer() function before you use GetVar() or SetVar() described below.
var name = player.GetVar("SL_Variable_Name"); ... directs JavaScript to get the value of whatever is stored in the custom Storyline variable called "SL_Variable_Name". Replace "SL_Variable_Name" with whatever your Storyline variable is called (notice the variable name must be placed in double quotes). "var name" is creating a custom JavaScript variable (not a Storyline variable) to store the value of the SL_Variable_Name in JavaScript. Replace "name" with whatever you want to call your JavaScript variable. Note the "player." before "GetVar". If you change the variable "player" above, be sure to change every occurrence of it in your JavaScript.
player.SetVar("SL_Variable_Name", name); ... directs JavaScript to send whatever is in your JavaScript variable, name, to your custom Storyline variable, SL_Variable_Name (again, I'm just using the variables "name" and "SL_Variable_Name" as examples). Notice that the Storyline variable is in double quotes but the variable containing the value you're sending to Storyline is not in quotes. Also notice again that "player." precedes SetVar.
Some additional explanation and sample code can be viewed at this link:
If you would like to describe what you're trying to do and post the JavaScript you're using in one of your Execute JavaScript triggers that isn't working, we can take a look.
Thanks for the Awesome information!