当弹出窗口没有出现时,视频弹出自动播放。我仍能听到声音

时间:2016-06-23 17:55:59

标签: javascript jquery iframe

我将此弹出窗口添加到我的网站,并尝试添加自动播放,但问题是每次刷新网站时都不会出现问题,您仍然可以听到声音。我可以在弹出时停止自动播放不显示?

我尝试通过这样做解决问题,但仍然无法正常工作

<script>
$( document ).ajaxComplete(function() {
    $("#popup_87 flex-video iframe").attr("src","https://www.youtube.com/embed/vYAVyEdBfEU?rel=0&autoplay=1;showinfo=0");
});
</script> 



    <!-- START POPUP CODE -->
    <div id="popup_87" class="reveal-modal small" data-reveal aria-labelledby="popvideo" aria-hidden="true" role="dialog">
        <div class="flex-video widescreen"> 
        <iframe src="https://www.youtube.com/embed/vYAVyEdBfEU?rel=0&amp;showinfo=0&amp;autoplay=1" allowfullscreen="" frameborder="0" height="360" width="640"></iframe>
        </div>
        <a class="close-reveal-modal" aria-label="Close">&#215;</a>
    </div>
    <div class="hide">
        <a href="#" class="clickMe" data-reveal-id="popup_87">popvideo</a>
    </div>

</div>

/////

<script>
    if (jQuery.cookie('popup{$popup['popup_id']}') === undefined)
    {
        var cookieCount = 1;
    }
    else
    {
        var cookieCount = jQuery.cookie('popup{$popup['popup_id']}');
    }
    var popCount = {$popup['popup_max_display_count']};
    if (cookieCount <= popCount) {
        setTimeout(function() {\$(".clickMe").trigger("click");}, 3000);
        cookieCount++;
        jQuery.cookie('popup{$popup['popup_id']}', cookieCount, { expires: {$popup['popup_clear_count_after']} });
    }
</script>

1 个答案:

答案 0 :(得分:1)

尝试

<script>
function LoadVideo() {
// If it's visible
    if($("#popup_87").is(":visible"))
    {
        // Load the video and auto play
        $("#popup_87 flex-video iframe").attr("src","http://www.youtube.com/embed/vYAVyEdBfEU?rel=0&autoplay=1;showinfo=0");
    }
}
</script> 

编辑,因为添加了更多代码,当他们点击链接时将触发器加载到弹出窗口中,否则请不要在iframe中加载视频:

<!-- START POPUP CODE -->
<div id="popup_87" class="reveal-modal small" data-reveal aria-labelledby="popvideo" aria-hidden="true" role="dialog">
    <div class="flex-video widescreen">
    <!-- Removed the source -->
    <iframe allowfullscreen="" frameborder="0" height="360" width="640"></iframe>
    </div>
    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
</div>
<div class="hide">
    <a href="#" class="clickMe" data-reveal-id="popup_87">popvideo</a>
</div>

我不确定以下代码是否有效,但我刚刚将LoadVideo添加到您的脚本中。

<script>
    if (jQuery.cookie('popup{$popup['popup_id']}') === undefined)
    {
        var cookieCount = 1;
    }
    else
    {
        var cookieCount = jQuery.cookie('popup{$popup['popup_id']}');
    }
    var popCount = {$popup['popup_max_display_count']};
    if (cookieCount <= popCount) {
        LoadVideo();
        setTimeout(function() {\$(".clickMe").trigger("click");}, 3000);
        cookieCount++;
        jQuery.cookie('popup{$popup['popup_id']}', cookieCount, { expires: {$popup['popup_clear_count_after']} });
    }
</script>