1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Possible to disable autoplay of iframe YouTube video with @media?

Discussion in 'XenForo Development Discussions' started by Kevin, Jan 26, 2014.

  1. Kevin

    Kevin Well-Known Member

    The lengthy title sums up what I am trying to do but, to clarify a bit, I have a template mod' that adds a YouTube video to an XF sidebar on a particular page. The video is set to autoplay. Using the @media definitions it is possible to turn off the display of the video but it still plays (because it is only suppressing the display of the content, not the inclusion of it).

    Any thoughts on being able to disabling the auto-play when the content is suppressed and/or disabling the inclusion of the content altogether based upon the browser size? I've been searching around but finding a viable solution.
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Have you tried setting an explicit width and height of 0 for the iframe?

    <style type="text/css">
    .iframe {
    width: 800px;

    <xen:if is="@enableResponsive">
    @media (max-width:910px) {
    .iframe {
    width: 0px;
    height: 0px
  3. Kevin

    Kevin Well-Known Member

    Thanks for the suggestion. I just gave it a try and while the 0-by-0 size suppresses the display it is still playing. I've got a funny feeling that to stop it the video from playing, or to completely disable the inclusion, I'll need some JS.
  4. Brogan

    Brogan XenForo Moderator Staff Member

    Oh, you actually want to stop it from playing too.
    I misunderstood.

    Presumably you've tried display:none ?

    Failing that, xen:comment would work but I don't think that's available in the css templates.

Share This Page