Javascript convert Cookie to Storyline Variable

Hi,

I am working on a project that requires loading cookie information into Storyline.

I write to a cookie from a javascript function in an embedded html page.(Web Object in Storyline)

I can read the cookie information into a JS variable in Storyline no problem.

The issue is converting the JS variable (with cookie information) into a Storyline variable.

Here is my JS in Storyline that currenly Alerts the cookies set and assigned to hotspotCookie. CookieValue is setup as a variable in Storyline:

var hotspotCookie = document.cookie;

alert("This is SL " + hotspotCookie);

player.SetVar("CookieValue", hotspotCookie);

 

Is there something I am doing wrong or is this incorrect?

 

 

2 Replies
Chad Keller

You're passing the full cookie string to Storyline which probably has more data than you need.  If you are looking to pass a value of a given cookie, you need to parse the string in javascipt and then pass the value of the cooke to Storyline.

This link has a javascript function that you could use to get a given cookie's value.

http://stackoverflow.com/a/15724300/1070235

And then really all you would need to do for your javascript Storyline would be this.

player.SetVar("CookieValue", getCookie('myCookieName');

Change myCookieName to whatever the actual cookie is that you are trying to target and it should set the value to the "CookieValue" Storyline variable.