gpt4 book ai didi

javascript - iframe YouTube多个视频跟踪

转载 作者:行者123 更新时间:2023-12-03 05:29:29 25 4
gpt4 key购买 nike

我有一个网页,其中嵌入了多个iframe youtube视频。

<html>
<body>
<iframe width="420" height="345" src="http://www.youtube.com/embed/video1"></iframe>
<iframe width="420" height="345" src="http://www.youtube.com/embed/video2"></iframe>
<iframe width="420" height="345" src="http://www.youtube.com/embed/video3"></iframe>
</body>
</html>

在脚本方面,我必须找到单击并开始播放的视频。

example: if a user click video1, then the script alert "http://www.youtube.com/embed/video1"

if a user click video2, then the script alert "http://www.youtube.com/embed/video2"

if a user click video3, then the script alert http://www.youtube.com/embed/video3



提前致谢。

最佳答案

您可以使用YouTube IFrame API(https://developers.google.com/youtube/iframe_api_reference)来响应视频状态更改。
向每个src添加?enablejsapi=1,设置api并查看onStateChange事件。

JSFiddle

关于javascript - iframe YouTube多个视频跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29005349/

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