【问题标题】:Hide iframe when Youtube video endsYoutube 视频结束时隐藏 iframe
【发布时间】:2014-09-25 10:36:08
【问题描述】:

提前谢谢大家。 我需要一些帮助以在 iframe youtube 视频结束时隐藏它,有人可以指导我如何做到这一点吗??

 <iframe id="promo_video" src="http://www.youtube.com/embed/XzZudNOwkU8" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="" style="display:none;position:absolute;top:228px;left:492px;" height="527" width="934" frameborder="0"></iframe>

我需要这样的东西,但我找不到如何制作它

 <script >
function myFunction()
{
    if (promo_video.end=positive)
    reload anotherother page


    }


</script>

【问题讨论】:

  • 太宽泛,没有细节,你试过什么?你遇到了什么问题?

标签: javascript iframe youtube


【解决方案1】:

希望此解决方案对您有用。解决方案的唯一变化是您只需要来自 iframe 的视频 ID。请参考下面提到的小提琴链接。

    <div id="player"></div>
<script src="http://www.youtube.com/player_api"></script>
<script>

    // create youtube player
    var player;
    function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'XzZudNOwkU8', <!-- video id should be here. last component from video URL -->
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
    }

    // autoplay video
    function onPlayerReady(event) {
        event.target.playVideo();
    }

    // when video ends
    function onPlayerStateChange(event) {        
        if(event.data === 0) {            
            $('#player').css('display', 'none');
        }
    }

</script>

Fiddle link

【讨论】:

  • 对 vimeo 视频有什么相同的吗?
猜你喜欢
  • 1970-01-01
  • 2014-09-30
  • 2019-06-19
  • 2019-03-24
  • 2020-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多