Forum Discussion
Execute JavaScript - passing object to script?
Hi,
Does the Execute JavaScript pass the object which executed the script, to the script in any way?
I'm trying to get hold of the object in JavaScript which calls the script in a easy way so if anyone knows of a way, please let me know!
Thanks,
PJ
- MathNotermans-9Community Member
And just posted a sample including some more info on this...
https://community.articulate.com/discussions/articulate-storyline/get-info-from-active-element-in-storyline - WaltHamiltonSuper Hero
You can set a variable in SL, and Get it in js.
For example, Adjust variable CallingObject set value = slide6button 1 when user clicks Button 1.
Execute js when user clicks Button 1.
Then js Gets CallingObject.
Seems pretty easy to me. After all, you have to create the trigger to execute the script, and the js is going to have the code to handle whatever calls it. All you have to do is to add the trigger to set the variable.
- ZsoltOlahSuper Hero
I'm not sure what exactly you mean by "object." The script you put in a JS trigger gets wrapped in a function and then executed from the user.js file based on the conditions and timing of the trigger. You can pass a variable using GetPlayer().GetVar() or set the SL variables using GetPlayer().SetVar(). Beyond that, you can't do too much. The only object you can interact with is the player.
- AVT-DigitalCommunity Member
Ah thanks for the replies. I was hoping that the object triggering the script would be passed down to the user.js as a DOM object which would allow for easy manipulation in JavaScript. But I did find this, which helped me to get around it: https://community.articulate.com/discussions/articulate-storyline/gsap-3-5-1-latest-version-is-now-included-in-storyline-360
- MathNotermans-9Community Member
As this post triggered me to see if i can find a way to get info of a clicked element with the help of Gsap in Storyline...i did.
Basically with this line of code you can get the active focused element in the DOM.var activeEl = document.activeElement;
With the help of the 'getProperty' function of GSAP you then can get any info you want from that element.var accName = gsap.getProperty(activeEl,"data-acc-text");
Then its easy to manipulate or get info from your document with GSAP.
If you want any other element on your page acting upon a specific buttonclick you can use the z-index to target any visible element in your Storyline.var elZindex = gsap.getProperty(activeEl, "z-index");
All elements in your timeline are on a specific z-index. The lowest is 1, numbering up.
Making a separate post showing it working... - mukeshbumb-0abaCommunity Member
I have embedded the video using video.js library and want to pass the value to storyline as soon as the video ended.
But not able to access the storyline player in video.js, so the GetVar(), SetVar() function is also not working. Atteched webobject file. If anyone knows, please let me know!
- Jürgen_Schoene_Community Member
try
<script>
const player = videojs('my-video');
player.on('ended', function(){
inform();
});
function inform() {
var playerSL = parent.GetPlayer();
playerSL.SetVar("s1_comp", "true");
}
</script> - mukeshbumb-0abaCommunity Member
No, it's not working.
- Jürgen_Schoene_Community Member
did you delete the webobject and reimport is - it is not possible to update a webobject
open the browser console (F12) - do you see any errors?
- mukeshbumb-0abaCommunity Member
- Jürgen_Schoene_Community Member
your example is working
disable trigger "when s1_com change" -> "jump to slide 1.3 S2"