Football Home Game
Sat, August 30, 2025
Sat, August 30, 2025
Basketball Home Game (MyUtahTV)
Sat, December 7, 2024 @ 7:00 pm
Sat, December 7, 2024 @ 7:00 pm
YouTube URL Parameters
- CodingAggieBlue
- Posts: 268
- Joined: November 3rd, 2010, 6:25 am
- Location: Logan, UT
- Has thanked: 486 times
- Been thanked: 33 times
YouTube URL Parameters
I was hoping to embed the following video in response to madmaxvol's post about the cfb trophy.
https://www.youtube.com/v/Yzht2_41caU?start=237&end=255
However when I went to preview my post, nothing showed up. I modified my URL as follows: https://www.youtube.com/v/Yzht2_41caU?v ... 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:
The result is the following URL: http://www.youtube.com/embed/Yzht2_41ca ... 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?
https://www.youtube.com/v/Yzht2_41caU?start=237&end=255
However when I went to preview my post, nothing showed up. I modified my URL as follows: https://www.youtube.com/v/Yzht2_41caU?v ... 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 = 'https://www.youtube.com/v/Yzht2_41caU?v=Yzht2_41caU&start=237&end=255';
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];
break;
} 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="http://www.youtube.com/embed/' + videoId + '?wmode=transparent' + usedparams + '"' + ' frameborder="0" wmode="Opaque" allowfullscreen></iframe><br /><a href="' + a + '" class="postlink-local" target="_blank">Watch on YouTube</a>');
</script>
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?
- treesap32
- Moderator
- Posts: 16921
- Joined: July 28th, 2005, 1:00 am
- Location: Washington D.C.
- Has thanked: 1267 times
- Been thanked: 2881 times
- Contact:
Re: YouTube URL Parameters
I would love to be able to control start and end time in our embedded youtube vids.