-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
37 lines (36 loc) · 1.13 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Embed youtube video in HTML</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="controls">
<input type="text" id="videoUrl" placeholder="Enter video URL" />
<button onclick="changeVideo()">Change Video</button>
</div>
<iframe
id="ytPlayer"
width="560"
height="315"
src="https://www.youtube.com/embed/a7cKMWsgGEM"
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen
></iframe>
<script>
function changeVideo() {
const url = document.getElementById("videoUrl").value;
const videoId = url.split("v=")[1]?.split("&")[0];
if (videoId) {
document.getElementById(
"ytPlayer"
).src = `https://www.youtube.com/embed/${videoId}`;
}
}
</script>
</body>
</html>