Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有IFrame问题的JQuery FancyBox(PHP)_Php_Jquery_Html_Iframe_Fancybox - Fatal编程技术网

带有IFrame问题的JQuery FancyBox(PHP)

带有IFrame问题的JQuery FancyBox(PHP),php,jquery,html,iframe,fancybox,Php,Jquery,Html,Iframe,Fancybox,大家好,我正在尝试在我制作的包含视频的页面中使用FancyBox,比如视频库,我的目的是将YouTube视频链接到其中 我遇到的问题是,它只是通过一个正常的a标签链接到年龄链接,而其他什么都不会发生 这是我用来生成视频的代码 while ($row = mysqli_fetch_assoc($result)){ echo " <div class='portalVideo'> <a clas

大家好,我正在尝试在我制作的包含视频的页面中使用FancyBox,比如视频库,我的目的是将YouTube视频链接到其中

我遇到的问题是,它只是通过一个正常的
a
标签链接到年龄链接,而其他什么都不会发生

这是我用来生成视频的代码

    while ($row = mysqli_fetch_assoc($result)){
         echo "
             <div class='portalVideo'>
                  <a class='fancybox fancybox.iframe' href='https://www.youtube.com/watch?v=DB7jsjt4Uec'>
                      <h3>
                          <strong>".$row["VideoName"]."</strong>
                      </h3>
                  </a>
             </div>";
    }
根据我的经验,我试着修复它。我的代码确实在head标记下面包含jquery

<script type="text/javascript">
    $(document).ready(function() {
        $('a.fancybox').fancybox();
    });
</script>

$(文档).ready(函数(){
$('a.fancybox').fancybox();
});
您有两个(与PHP无关)问题:

1) 。此youtube格式:

。。。。在
iframe
中不受支持,因为它很可能包含
DENY
响应头。您可能需要将其转换为嵌入格式,如:

https://www.youtube.com/embed/DB7jsjt4Uec 
2) 。只有在fancyboxv2.x中才支持特殊类
fancybox.iframe
,但您似乎正在使用fancyboxv1.3.x。因此,您宁愿使用类
iframe
或添加API选项

type: "iframe"
。。。到您的自定义fancybox初始化脚本

由于您正在从数据库中提取视频链接,好消息是您不必在PHP代码中更改任何内容,只需在jQuery代码中更改,如:

jQuery(document).ready(function ($) {
    $(".fancybox").each(function (i) {
        // change links on the fly to embed format
        this.href = this.href.replace(new RegExp("watch\\?v=", "i"), 'embed/') + "?autoplay=1";
    }).fancybox({
        // API options
        type: "iframe" // needed for videos embed format
    });
}); // ready
注意我正在将
?autoplay=1
添加到新的
href
中,但如果您希望视频
自动播放
在fancybox的
iframe
中播放一次,这是可选的

type: "iframe"
jQuery(document).ready(function ($) {
    $(".fancybox").each(function (i) {
        // change links on the fly to embed format
        this.href = this.href.replace(new RegExp("watch\\?v=", "i"), 'embed/') + "?autoplay=1";
    }).fancybox({
        // API options
        type: "iframe" // needed for videos embed format
    });
}); // ready