JavaScript – YouTube Live, Chat

Can you help me write simple code in JavaScript. I haven’t studied the intricacies of the code and don’t want to delve into the details. I need to connect the chat to the broadcast.

The page contains a live broadcast from YouTube located in an <iframe>.

<iframe width="560" height="315" src="https://www.youtube.com/embed/live_stream?channel=UCM-n0BKVvTOxC45B4yxZQpA" frameborder="0" allowfullscreen></iframe>

From <iframe> you need to get the video identifier. Once it has been opened to the user.

In <iframe> → <head> you need to copy the video identifier.

<link rel="canonical" href="https://www.youtube.com/watch?v=I0Km7xrqN-g">

And replace the video identifier in chat

<iframe height="500" width="300" src="https://www.youtube.com/live_chat?v=I0Km7xrqN-g&embed_domain=stackoverflow.com" style="border: 0; width:300px; height:100px; background-color: transparent;"></iframe>

Sample code

<iframe id="yt" width="560" height="315" src="https://www.youtube.com/embed/live_stream?channel=UCM-n0BKVvTOxC45B4yxZQpA&autoplay=1" frameborder="0" allowfullscreen></iframe>
<iframe id="chat" height="500" width="300" src="https://www.youtube.com/live_chat?v=<IDVideo>&embed_domain=stackoverflow.com" style="border: 0; width:300px; height:100px; background-color: transparent;"></iframe>
<script>

</script>

<link rel=”canonical” href=”https://www.youtube.com/watch?v=I0Km7xrqN-g“>

<IDVideo> → I0Km7xrqN-g


It is not possible to use .php since the resource is hosted on https://github.io/ I’m self-taught, but I’ve seen a lot of things JavaScript does. And I think it is possible to do. This is all due to the fact that the video identifier is unique for each broadcast. And there is no universal link for the chat.

I would be happy if I knew. But for me it’s hard. I will be grateful if you can help.