3 Replies
Ashley Terwilliger

Hi Sagar,

I haven't seen a lot of examples where the Javascript was embedded into a web object, and as it's something we don't offer support for, I'll have to defer to the community for additional assistance. I have seen some threads where the Javascript was used to open the web object and you may want to investigate this thread and this one, perhaps even reaching out to those users to see if they're able to assist you further. 

Will Findlay

Here is some code you can use to do this. Insert this into your storyline file as a webobject... For some reason using a boolean variable doesn't work well in Storyline, so I just use a Text variable. Here is example: https://360.articulate.com/review/content/c0db799e-4921-4dbc-8fa4-00c38edbb76b/review

 

<html>
<head>
<style>
html, body {
margin: 0 0 0 0;
overflow:hidden;
}
</style>
</head>
<body>
<div id="player"></div>

<script src="https://www.youtube.com/player_api"></script>

<script>

// create youtube player
var isComplete = false;
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '100%',
width: '100%',
playerVars: {rel:0},
videoId: '_kwZ-xeOj8Y',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}

//autoplay video
function onPlayerReady(event) {
event.target.playVideo();
}

// when video ends
function onPlayerStateChange(event) {
if(event.data === 0) {
var isComplete = true;
console.log(isComplete);
var player = parent.GetPlayer();
player.SetVar("videoIsComplete","Yes");
}
}

</script>
</body>
</html>