自iOS6以来,Fancybox不显示YouTube视频

时间:2012-11-13 11:16:00

标签: javascript youtube fancybox

这是我去年使用的代码。它很棒!

$("#videos a").click(function() {
    if ($(this).hasClass('youtube')) {
        $.fancybox({
            'padding'       : 0,
            'autoScale'     : false,
            'transitionIn'  : 'none',
            'transitionOut' : 'none',
            'title'         : this.title,
            'width'         : $(this).attr('data-width'),
            'height'        : $(this).attr('data-height'),
            'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'          : 'swf',
            'swf'           : {
                'wmode'     : 'transparent',
                'allowfullscreen'   : 'true'
            }
        });

        return false;
    }
});

在iPad上使用此代码时,将显示视频。如果在iPad上无法观看视频,您会看到带有划掉播放按钮的YouTube图标。

从iOS6开始,这已经停止了。代码中没有任何内容发生变化。相反,你现在看到一个白色的弹出窗口。有人遇到过这个吗?有谁知道原因?

我正在使用Fancybox 1.3.4

1 个答案:

答案 0 :(得分:9)

要让您的YouTube视频在不​​同平台上更易于访问,您应该停止使用格式http://www.youtube.com/watch?v=3l8MwU0IjMI(使用 swf 播放器),而是使用embed方法(您可以从youtube中选择share标签

获取正确的代码

所以,而不是:

<a class="fancybox" href="http://www.youtube.com/watch?v=3l8MwU0IjMI">open youtube video in fancybox</a>

......这样做:

<a class="fancybox" href="http://www.youtube.com/embed/3l8MwU0IjMI?autoplay=1">open youtube video in fancybox</a>

然后修改您的fancybox(v1.3.4)脚本以打开内容typeiframe,如

$(".fancybox").fancybox({
 "width": 620, // or whatever
 "height": 420,
 "type": "iframe"
});