Javascript 点击yt视频时加载js功能?
一旦点击Yt视频开始,是否可以执行Java脚本功能 我的代码如下所示:Javascript 点击yt视频时加载js功能?,javascript,html,onclick,embed,yt,Javascript,Html,Onclick,Embed,Yt,一旦点击Yt视频开始,是否可以执行Java脚本功能 我的代码如下所示: <html> <head><title>onclick event demo</title> </head> <body> <h3>onclick event demo</h3> <p>Fires when the element is clicked.</p> &
<html>
<head><title>onclick event demo</title>
</head>
<body>
<h3>onclick event demo</h3>
<p>Fires when the element is clicked.</p>
<embed
onclick="VideoStart()"
src="https://www.youtube.com/embed/qK9v-VFfdY0?start=478" style="border:1px solid;"
>
</body>
</html>
<script>
function VideoStart(){
***code executed when clicking on the Yt-Video***
}
</script>
onclick事件演示
onclick事件演示
单击元素时激发
函数VideoStart(){
***点击Yt视频时执行的代码***
}
但由于某种原因,当我用鼠标点击启动或停止YT视频时,什么都没有发生。有人能帮我做这个吗。我希望您能回答。
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://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: '360',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
//event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
myFunction();
}
}
function stopVideo() {
player.stopVideo();
}
function myFunction(){
alert("Hello world");
}
</script>
</body
// 2. 此代码异步加载IFrame播放器API代码。
var tag=document.createElement('script');
tag.src=”https://www.youtube.com/iframe_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
// 3. 此函数用于创建(和YouTube播放器)
//API代码下载后。
var播放器;
函数onyoutubeiframeapiredy(){
player=新的YT.player('player'{
高度:'360',
宽度:“640”,
videoId:'M7lc1UVf VE',
活动:{
“onReady”:onPlayerReady,
“onStateChange”:onPlayerStateChange
}
});
}
// 4. 当视频播放器准备就绪时,API将调用此函数。
函数onPlayerReady(事件){
//event.target.playVideo();
}
// 5. 当播放器的状态改变时,API调用此函数。
//该功能指示播放视频时(状态=1),
//玩家应该玩六秒钟,然后停下来。
函数onPlayerStateChange(事件){
if(event.data==YT.PlayerState.PLAYING){
myFunction();
}
}
函数stopVideo(){
player.stopVideo();
}
函数myFunction(){
警报(“你好世界”);
}