Embedding YouTube Player with SWFObject

November 11th, 2009 by Alex Leave a reply »

If you host your videos on YouTube as many people do, than you may need to show the video on your website. This is very, very simply actually. All you need to do, is load the SWFObject library, and embed the video in this way:

<script type="text/javascript" src="js/swfobject.js"></script>
<div id="ytapiplayer"></div>
<script type="text/javascript">
swfobject.embedSWF("http://www.youtube.com/v/j7y_6JHUDR0?enablejsapi=1&amp;version=3&amp;border=0", "ytapiplayer", "576", "356", "8", null, null);
</script>

This is called the YouTube JavaScript Player API and can be used freely on any website. Just replace the video id after http://www.youtube.com/v/ and embed your own video.

Here is the result of the script below.

This page can be found by searching for:

swfobject youtubeyoutube swfobjectswf object youtubeswfobject youtube videoswfobject embedswf youtubeswfobject embed youtubeswfobject youtube playerswfobject and youtubeswfobject with youtube



1 comment

  1. I really like youtube but yeah it does have some bad points. Like with illegal material and things.