YouTube URL Parameters

We want this to be the best online community of Aggie fans in the world. If you know of something that will make it better, let us know.
User avatar
Posts: 261
Joined: November 3rd, 2010, 6:25 am
Location: Logan, UT
Has thanked: 284 times
Been thanked: 23 times

YouTube URL Parameters

Post by CodingAggieBlue » July 15th, 2014, 10:16 pm

I was hoping to embed the following video in response to madmaxvol's post about the cfb trophy.

However when I went to preview my post, nothing showed up. I modified my URL as follows: ... 37&end=255. This tricks the inserted Javascript code into embedding my URL. However, it still strips off the other URL parameters.

I wanted to use the YouTube URL parameters described here. Specifically I wanted to use the start and end parameters to limit which section of the video would play. I believe that this can be done by modifying the code as follows:

Code: Select all

Disabled language="Javascript">
	var allowedparams = ['start', 'end'];
	var usedparams = '';
	var a = '';
	var temp = new Array();
	temp = a.split('?');
	variablestring = temp[1];
	variables = variablestring.split('&');
	for(var i in variables){
		variable = variables[i].split('=');
		if(variable[0] == "v"){
			videoId = variable[1];
		} else if (allowedtags.indexOf(variable[0]) > -1) {
			usedparams.concat('&' + variables[i]);
	document.write('<iframe style="z-index:1;" title="YouTube video player" width="640" height="390" src="' + videoId + '?wmode=transparent' + usedparams + '"' + ' frameborder="0" wmode="Opaque" allowfullscreen></iframe><br /><a href="' + a + '" class="postlink-local" target="_blank">Watch on YouTube</a>');
The result is the following URL: ... 37&end=255. This adds the functionality I'm looking for, but doesn't drastically change how things are currently working.

I recognize that not all YouTube parameters are desirable (such as autoplay). You can limit what parameters are accepted using the allowedparams array.

Note, I haven't actually tried to run the code above so it might not work as-is. You might also need to do some additional sanitizing of variablestring to prevent code injection. However, the general idea should work. Any thoughts?

User avatar
Posts: 16742
Joined: July 28th, 2005, 1:00 am
Location: Washington D.C.
Has thanked: 1095 times
Been thanked: 2601 times

Re: YouTube URL Parameters

Post by treesap32 » July 16th, 2014, 7:53 am

I would love to be able to control start and end time in our embedded youtube vids.

Post Reply Previous topicNext topic