Rotation of Videos using Javascript

Step 4: Make the Function More Generic

We need to parameterize the writeVideoCode() function so that it accepts three parameters: the Flash video URL, the width, and the height. We give them the names url, w, and h respectively and replace the hard-coded values with these variable in the video code snippet.

That also means that we need to pass in the original specific values in our function call. Our function call in the body onload event becomes...

Since we want the same video to play when the user clicks the 'Juggling' link, we make the same javascript function call in the href of the link as shown...

For the "Graduation Song" and the "Pixar Cars" videos obtained at YouTube.com from here and here, we pass in the two different URLs as shown...

Now as the user clicks the three links, the function will write out the appropriate video code and video will play.

View Live Code Here

Next Lesson:

  Rotating the Video