youtube embed code code example
Example 1: how to embed videos in html
<iframe src="example.mp4" width="100px" height="100px"></iframe>
Example 2: youtube embed video
//Author:Mohammad Arman Khan
<div>
<iframe class="videoframe" src="https://www.youtube.com/watch?v=VfGW0Qiy2I0">
</iframe>
</div>
Example 3: get youtube embed code from url
<----------------------------------- HTML ---------------------------------->
YouTube ID: <span id="myId"></span>
<br />
<br />
Embed code: <pre id="myCode"></pre>
function getId(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
return 'error';
}
}
<----------------------------------- JS ---------------------------------->
var myId = getId('http://www.youtube.com/watch?v=zbYf5_S7oJo');
$('#myId').html(myId);
$('#myCode').html('<iframe width="560" height="315" src="//www.youtube.com/embed/' + myId + '" frameborder="0" allowfullscreen></iframe>');
Example 4: embedded youtube
<iframe id="ytplayer" type="text/html" width="640" height="360"
src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
frameborder="0"/>
Example 5: html inbed youtube
Search up "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
#real code
<body>
<iframe width="420" height="345"
src="https://www.youtube.com/watch?v=dQw4w9WgXcQ">
</iframe>
</body>
Example 6: iframe youtube playlist not working html
<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PLQGSXoAiT2W4W8D3397nl4OB_GxfOmJk9" allowfullscreen></iframe>