gpt4 book ai didi

javascript - 当 YouTube 视频结束时,如何显示弹出窗口/弹出窗口?

转载 作者:行者123 更新时间:2023-11-29 14:59:04 24 4
gpt4 key购买 nike

我正在尝试找出一种在 YouTube 视频结束时触发 javascript 模式弹出窗口/弹出窗口的方法。

我第一次看到这个是在 UpWorthy.com 上实现的。有关视频结束时的示例,请参阅此视频:http://www.upworthy.com/bully-calls-news-anchor-fat-news-anchor-destroys-him-on-live-tv

我通过将 JS 参数添加到嵌入代码 (enablejsapi=1) 来启用 javascript api

我正在使用这个简单模态脚本来实现模态:http://www.ericmmartin.com/projects/simplemodal/

如何让 YouTube 视频结束以触发它?

非常感谢

最佳答案

<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>

关于javascript - 当 YouTube 视频结束时,如何显示弹出窗口/弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12849742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com