如何获取带有嵌入式 Vimeo 视频的页面以卸载视频并在视频播放完毕后重定向到另一个页面?

How do I get a page with an embedded Vimeo video to unload the video and redirect to another page once the video has finished playing?

我找到了重定向部分(我想......见下文),但问题是当我返回带有嵌入视频的页面时,它立即将我传送到重定向页面。所以我想如果我可以在重定向发生之前让视频卸载或重置到视频的开头,那么我就会解决这个问题。

想法?

<div class="video"><iframe src="https://player.vimeo.com/video/253989945?byline=false&playsinline=0&portrait=false&title=false" frameborder="0" allow="autoplay; fullscreen" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
<script src="https://player.vimeo.com/api/player.js"></script>
<script>
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.getEnded().then(function(ended) {
  // `ended` indicates whether the video has ended
   window.location.replace("http://www.google.com/");
});
</script>

当您应该使用事件侦听器时,您不应该使用 getter。此外,您没有使用条件判断视频是否已结束。

像这样的东西应该可以达到这个目的:

var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);

player.on('ended', function() {
    console.log('ended')
    window.location.replace("https://www.google.com/");
})