Hide Next Button until HTML-embedded iFrame video is finished playing | Experience Community
Skip to main content
Solved

Hide Next Button until HTML-embedded iFrame video is finished playing

  • Jun 15, 2023 2:29 PM UTC
  • 3 replies
  • 976 views

JonesE
Level 4 ●●●●
Forum|alt.badge.img+27

I have a survey which asks respondents to view a video in entirety before proceeding to answer questions on the next page. I would like to hide the next button until the video is finished playing. Of note, I specifically don’t want to use a timer to hide the next button in case someone chooses to watch the video on a higher watch speed (e.g., 1.5x, 2x).

I’ve poured through the Community Forum looking for Javascript to accomplish this; however, my issue seems to be with using iFrame as the code I’ve found is written for other embedded video formats.

Does anyone have any experience with using JS with iFrame videos in Qualtrics? Thank you!!

Best answer by krbhavya

Hi @JonesE 

Found a post related to your query . Hope this resolves it.

 

 

View original

3 replies

Forum|alt.badge.img+15
  • QPN Level 4 ●●●●
  • Jun 15, 2023 3:17 PM UTC

Hi @JonesE,

 

Not sure if you have already tried getting iframe content, writing inside <div> element and then use the embedded code you have. Code for getting content of iframe is…

 var frameObj = document.getElementById(frameId);
var frameContent = frameObj.contentWindow.document.body.innerHTML;

 Hope it helps.

Thanks,

JB


JonesE
Level 4 ●●●●
Forum|alt.badge.img+27
  • Author
  • Level 4 ●●●●
  • Jun 15, 2023 9:11 PM UTC

Thanks, @Jagdish! My colleague attempted this already, but it’s still not working. I’ve pasted her code below:

Qualtrics.SurveyEngine.addOnload(function() {
this.hideNextButton();
});



Qualtrics.SurveyEngine.addOnReady(function() {
var iframe = document.getElementById("video-player");
var that = this;



iframe.addEventListener("load", function() {
var videoPlayer = iframe.contentWindow.document.querySelector("video");



videoPlayer.addEventListener("ended", function() {
that.showNextButton();
});



videoPlayer.addEventListener("timeupdate", function() {
if (isVideoNearEnd(videoPlayer)) {
videoPlayer.pause();
that.showNextButton();
}
});
});



function isVideoNearEnd(player) {
var currentTime = player.currentTime;
var duration = player.duration;
var threshold = 1.5; // Adjust this threshold as needed



return currentTime >= duration - threshold;
}
});

 


krbhavya
Level 6 ●●●●●●
Forum|alt.badge.img+20
  • Level 6 ●●●●●●
  • Answer
  • Jun 16, 2023 6:41 AM UTC

Hi @JonesE 

Found a post related to your query . Hope this resolves it.