Javascript not writing cookies
Jan 18, 2015
I want to pass some information in my Storyline course back to an application. Seems this is simply done by writing a cookie, then jumping to the url and having my program read the cookie.
Problem is my cookies are not getting written. Any suggestions on how to write a cookie using JavaScript in Articulate Storyline?
My first trigger on the slide is:
When timeline starts execute JavaScript
JavaScript code is:
var player = GetPlayer();
var Scorepoints = player.GetVar("Resuts.scorepoints");
document.cookie = "scorepoints" + "=" + scorepoints + "; "
document.cookie="testcookie=John Doe";
Neither cookie is written.
3 Replies
Never mind the typo in the results variable name. You cannot directly reference Results.xyz variables in JavaScript. You need to put the value of Results.ScorePoints into a Storyline custom variable and then reference that variable in your script.
That is great info on the player variables. I was able to set the results.scorepoints to my own variable and then display it in a pop-up. My only issue now is getting a cookie written.
For testing I am writing a generic cookie statement with no variables. When I run a program which lists all cookies in my browser it is never there. This is what is in my Storyline trigger:
var player = GetPlayer();
var Passpercent = player.GetVar("passpercent");
var Scorepercent = player.GetVar("scorepercent");
document.cookie="Mycookie=Ramon";
alert("Your new score is " + Scorepercent);
Is there a special way we need to write a cookie in storyline? This seems pretty straight forward.
I should have a cookie named "Mycookie" with a value of "Ramon". No cookie.
I figured out how to get Storyline to write a cookie. You have to include the Path parameter.
typical JavaScript cookie syntax is:
document.cookie="Mycookie=Ramon";
Syntax in Articulate Storyline is:
document.cookie='Mycookie=Ramon;path=/';
This discussion is closed. You can start a new discussion or contact Articulate Support.