Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:33:51+00:00 2026-06-09T14:33:51+00:00

On my site, I have a static-width embedded chromeless YouTube player (iframe) that plays

  • 0

On my site, I have a static-width embedded chromeless YouTube player (iframe) that plays a video selected by the user. It’s working well, but there’s one little annoyance: its height does not respond to the video; cinematic ultra-widescreen videos have horizontal black bars and old-style 4:3 videos have vertical black bars.

Is there a reasonably simple solution that will make the player adjust its height according to the video it’s playing? All Google reveals are scripts for fluid-layout sites (which mine is not). Javascript, Coffeescript, and Jquery solutions are all acceptable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:33:52+00:00Added an answer on June 9, 2026 at 2:33 pm

    In order to achieve your expected behavior, you need to know the video’s aspect ratio. You can do that quite easily using the API YouTube provides. First, to grab the video info in JSON format, you GET a URL of this form:

    https://gdata.youtube.com/feeds/api/videos/video_id?v=2&prettyprint=true&alt=json

    Where video_id is the ID of the video you’re embedding (note that “prettyprint” just makes it human-readable — remove it in the actual application to save bandwidth). The property that we care about is entry.media$group.yt$aspectRatio.$t. That property is set to “widescreen” when the video is 16:9, and it isn’t defined if it’s 4:3. Thus, you can easily check for that value and resize your <iframe> accordingly.

    Here’s an example:
    HTML:

    <iframe id = "vid" width="500" src="http://www.youtube.com/embed/ni9RS4pgRXA" frameborder="0" allowfullscreen></iframe>
    

    (Width here is 500 — it can be, of course, anything you want).

    JavaScript (uses jQuery, but it isn’t necessary):

    $.getJSON("https://gdata.youtube.com/feeds/api/videos/ni9RS4pgRXA?v=2&alt=json",
    function(data) {
                var obj = $("#vid");
                var asp = data.entry.media$group.yt$aspectRatio.$t;
                console.log("Aspect Ratio is", asp); //Debugging line. "undefined" if video is 4:3.
                if(asp == "widescreen") {
                    obj.height((Math.floor(obj.width() * 9 / 16)));
                }
                else {
                    obj.height((Math.floor(obj.width() * 3 / 4)));
                }
            });
    

    Here (link) you can find a working demo with an example 16:9 video. The Javascript code is pretty straight-forward, but in case anything is vague, please tell me so that I can explain in more detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site that I'm creating, part in static HTML, the other part
I have an ASP.net site that is essentially just a user interface for a
I am adding this simple plugin that I have working in a static html
I have a static HTML site that is going to run off CD. It's
I have a site with some static pages that lie in à folder called
I have some static content on my web site that I have set up
We have to develop an Ecommerce site with 20+ pages of static content which
I have many static images under a directory in my site structure, and I'm
I have developed a site, which has some static pages. Like explore, home, feedback.
I have site I am working on and the images take forever to load,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.