Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thought I'd share how I stop iframe > video from playing after closing Tobii #25

Closed
marcamos opened this issue Jun 15, 2020 · 1 comment

Comments

@marcamos
Copy link

marcamos commented Jun 15, 2020

Hello,

I'm in the process of building a page where Tobii launches a Vimeo video. As Vimeo doesn't seem to be supported in the same way that YouTube is, I fell back to using the iframe feature of Tobii, and it works well.

What I then discovered is…

  1. The Vimeo video is launched in the lightbox
  2. The visitor presses play
  3. When the visitor wants to stop watching, they close Tobii
  4. At this point, the video is still playing – it's merely hidden, but it can still be heard

So, I had to determine how to stop a video after the visitor clicks Tobii's close button, or its backdrop. This is what I came up with and it seems to work well:

new Tobii()

const initCustomTobii = function() {
  document.querySelector('.tobii__close')?.addEventListener('click', handleTobiiIframes)
  document.querySelector('.tobii__slider')?.addEventListener('click', handleTobiiIframes)
}

const handleTobiiIframes = function() {
  const tobiiIframes = document.querySelectorAll('.tobii iframe')
  if (tobiiIframes) {
    tobiiIframes.forEach(function(iframe) {
      let src = iframe.src
      iframe.src = src
    })
  }
}

initCustomTobii()

I thought I'd share this in case it's helpful to others.

@viliusle
Copy link
Collaborator

viliusle commented Jul 1, 2021

It is fixed in latest version. Vimeo can be used with iframe now without additional coding. Check demo.

@viliusle viliusle closed this as completed Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants