Forum Discussion
Send variables from web object
Hi,
I'm trying to send a variable from a web object to storyline to display that value on the screen. In my web object HTML page, I have this:
let testVar = "Hello World"
In my storyline file I have a variable of the same name on the stage to show the content of the passed in variable. Storyline is told to run the JS on slide startup with this JS:
let player = GetPlayer();
player.GetVar('testVar');
I can't get the variable to show. What am I doing wrong?
Thanks :)
- OwenHoltSuper Hero
Web objects may or may not be on the same domain and so this breaks cross domain security protocols. You could try to have the web object page send the value to local storage but something IN the web object page would have to trigger this. Maybe an On Load event to kick off the JavaScript needed to store values in local. <body onload="myFunction()">
Once that has occurred, you can have Storyline pick up the values from local storage and display them in a Storyline variable. Again, you would need some event to kick off this 2nd piece of JS coding.While what you are attempting may seem like it should be a simple thing, it is not.
- Jürgen_Schoene_Community Member
(1) you have imported the webobject the wrong way
create a folder and insert the index.html, then import the folder - NOT the index.html
(2) if you publish, the webobject will be inserted as an iframe, so you need "parent." to connect to storyline
(3) GetVar() is wrong, you need SetVar() to change the variable in storylinelet value = "Hello World"
if (!parent.GetPlayer) {
console.error( "storyline player not found" );
} else {
let player = parent.GetPlayer();
player.SetVar('testVar', value );
}
result:
https://360.articulate.com/review/content/9d6090df-4a37-4c27-9ade-2604c8113e05/reviewImportant: If you change anything in the webobject, you have to delete the webobject in storyline and reimport it - there is no autoupdate