youtube视频结束时显示弹出窗口

时间:2014-05-09 23:23:03

标签: php facebook wordpress video youtube

我需要在youtube视频停止时显示弹出窗口(Facebook分享框)。 我的wordpress网站上已有很多视频。我需要这个才能用于我以前的所有视频。 我已经在另一篇文章中试过了这个:

<html>
<head>
<title>YT Test</title>
<script type="text/javascript">
  <!--
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player) after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'ecccag3L-yw',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }

      // The API will call this function when the video player is ready.
      function onPlayerReady(event) { /* do nothing yet */ }

      // The API calls this function when the player's state changes.

      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.ENDED) {
                // insert appropriate modal (or whatever) below
                alert('I hope you enjoyed the video')
        }
      }
      -->

</script>
</head>
<body>
<div id="player"></div>
</body>
<html>

没有帮助。这仅适用于一个视频。 ecccag3L-yw在这种情况下。 有人可以帮我做到这一点吗? 这是我需要的一个例子。 http://www.broascadilie.ro/index.php/video/item/29208-c%C3%A2nd-ea-are-chef-%C8%99i-tu-nu-when-she-is-in-the-mood-and-he-isnt 在视频结束后,会出现一个弹出窗口供用户喜欢和/或分享。

1 个答案:

答案 0 :(得分:0)

这个并不难。您需要将videoId: 'ecccag3L-yw'更改为videoId: '<?php echo $id?>'

此外,您需要确保在$id变量中存储您的视频ID。由于您使用的是wordpress,因此您应该只建立与数据库的连接并获得您感兴趣的值。 所以在<title></title>

之后