2007·06·11 · 11 Comments
How I Did It: YouTube

Update: new, improved explanation.

I'm no computer tech nerd. My web skills are really quite basic, gained largely through trial & error and by clicking "view page source" on web pages with interesting features. But I'm a fiddler and a tinkerer, so I can seldom just leave a newly-discovered function alone without customizing it. That's not always a good thing. I've messed up a lot of perfectly good code by trying just one more modification. Sometimes though, I have a genuine "Eureka!" moment when I figure out something really good. Today, I want to share one of those "Eureka!" moments. The techies out there will be mostly unimpressed, but perhaps some of you will find this useful.

computernerd.pngI don't like sending readers to sites with questionable content. For that reason, I prefer to embed YouTube videos rather than link to YouTube. However, embedded videos are one of the things that can cause your page to load slowly. Also, they clutter up the appearance of the page. I therefore wanted to make the video open alone in a popup window.

First, I scavenged the code frome a page containing a popup image. In this case, it was from my own site. (Movable Type allows you to choose "popup" or "embedded" when uploading a file, and writes the code for you, so yes, I had done it before without knowing how.) Then I trimmed out the attributes I didn't need, such as scrollbars and the like. I then simply replaced the file URL with the YouTube video URL. This will not be the URL found in the address bar or to the right of the video on the YouTube page. It will be the URL found in the "embed" code directly below that, highlighted in red in this image. YouTube will not let you copy just the URL out of the "embed" code, so you will have to copy & paste the entire "embed" code and then copy the URL into your popup code. Just right-click on the "embed" code and click "copy." Then paste it into your blog post or any document. It will look like this:

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/yBsGFAXw6d4"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/yBsGFAXw6d4" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

The URL is the part in red type, and is the only part you will keep. Delete the rest. The code you need, with the URL copied from the code above, looks like this:

<a href="http://www.youtube.com/v/yBsGFAXw6d4" onclick="window.open('http://www.youtube.com/v/yBsGFAXw6d4','popup', 'width=425, height=350'); return false">Where I learned My Computer Skills</a>

. . . and here's how it works:

Where I learned My Computer Skills

Now, here's another trick to give you further control over your content, this one thanks to the Desiring God blog. YouTube videos are automatically followed by a menu of related videos that you may or may not want appearing on your site. You can eliminate them by simply adding &rel=0 to the URL, like this:

http://www.youtube.com/v/yBsGFAXw6d4&rel=0

Finally, you can adjust the size of the video display by changing the width & height attributes, or go to full screen by simply omitting them. However, most YouTube videos are not of high enough resolution to display at full screen.

As I said, techies will be generally unimpressed with this, but my little brain thinks this is very cool. I hope someone finds it useful.

11 Comments:

1. 07·06·12··12:56
Daniel

I salute you sir. Bravo!

2. 07·06·12··18:42
David

Thank you, thank you very much. Yes, I am becoming quite a hacker. Now, where's the "Any" key?

3. 07·06·13··11:54
Lance M. Roberts

Thank you! I am much less of a computer whiz than you. This is helpful. I am wondering how to get 3 columns on my blog such as you have. Do you have any secrets on that?

4. 07·06·13··22:11
David

Lance,
I use a table. I think that is looked down on by most computer pros, but it forces the template to do what I want in all browsers,so I like it. I can email you with more details if you like.

5. 07·06·14··02:17
Lance M. Roberts

David,

Great. Please do email it. Thank you!

6. 07·06·14··05:19
Garry Weaver

I read all that and I still don't have a clue. I'm not sure if your explanation is at fault, or if it's the "old dog new tricks" thing.

7. 07·06·14··18:58
David

Garry,

Probably my explanation.

I've updated my post just for you.

8. 07·06·14··19:00
David

Lance,

I'll do that as soon as I have time. Feel free to remind me.

9. 07·06·16··10:00
Brendt

I'm a techie, and I'm impressed.

Re: tables. While it is looked down upon by most computer pros, the alternative is to make massive accommodations in your code to account for the fact that -- big surprise -- Microsoft doesn't write IE to be compliant with standards that were written several years ago.

I don't want to be a Redmond enabler, so I use tables where I "shouldn't", too.

10. 08·08·02··03:32
John Muscat

May you be forever blessed my friend!!!
I tried hundreds of complicated scripts to get what you did in just a few simple lines!! Believe me, you got tears in my eyes!!!!!! THANKS THANKS THANKS

11. 08·08·02··10:16
David

Glad I could be of some use. Dry your eyes, now.


Comments on this post are closed. If you have a question or comment concerning this post, feel free to email us.