Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Google Gadget to embed YouTube videos.
<?xml version="1.0" encoding="UTF-8"?>
<ModulePrefs title="YouTube iframe embed" author="Stefan Sundin" width="640" height="390"></ModulePrefs>
<UserPref name="id" datatype="string" default_value="" />
<UserPref name="width" datatype="string" default_value="" />
<UserPref name="height" datatype="string" default_value="" />
<UserPref name="args" datatype="string" default_value="" />
<Content type="html">
<script type="text/javascript">
var prefs = new gadgets.Prefs();
var width = prefs.getString("width");
var height = prefs.getString("height");
var args = prefs.getString("args");
var video_id = prefs.getString("id");
if (!window.innerWidth && document.body.offsetWidth) {
window.innerWidth = document.body.offsetWidth;
window.innerHeight = document.body.offsetHeight;
if (width == "") {
if (window.innerWidth) {
width = window.innerWidth;
height = window.innerHeight;
else {
width = 640;
height = 390;
var iframe = document.createElement("iframe");
iframe.setAttribute("class", "youtube-player");
iframe.setAttribute("type", "text/html");
iframe.setAttribute("seamless", "seamless");
iframe.setAttribute("frameborder", 0);
iframe.setAttribute("width", width);
iframe.setAttribute("height", height);
iframe.setAttribute("src", ""+video_id+(args?"?"+args:""));
/* Developer notes:
Example use (Google Project Hosting):
<wiki:gadget border="0" url="" up_id="LLtxSkoWKfc" width="640" height="390" />
<wiki:gadget border="0" url="" up_id="LLtxSkoWKfc" width="1280" height="750" up_args="start=8" />
<wiki:gadget border="0" url="" up_id="LLtxSkoWKfc" width="1280" height="750" up_args="start=8&rel=0" />
width/height combinations and resulting default quality:
560x345 (320p)
640x390 (320p)
853x510 (480p)
1280x750 (720p)
1920x1110 (1080p)
You can also use parameters up_width=1280 up_height=750 to override detection code.
You can specify the parameter "args" if you want to give the player additional arguments.
List of available arguments here:
One useful argument is "start" which specifies where in the video to start playing.
Separate arguments with "&".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.