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 8060487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:00:33+00:00 2026-06-05T10:00:33+00:00

I have a simple page with an embedded video. Below is an example. I

  • 0

I have a simple page with an embedded video. Below is an example. I want to retrieve the width of the embedded video’s iframe, which can vary ( for example if the video is from youtube or vimeo ). Then I can put a div next to it, with some text, and adjust the width of the latter accordingly

<html>
  <head>
  </head>
      <body onLoad = "resizeElements()">
    <iframe width="420" height="315" src="http://www.youtube.com/embed/a34QTcpnKww"     frameborder="0" allowfullscreen>
    </iframe>  
  </body>
    <script language="JavaScript" type="text/javascript">
    function resizeElements() 
    {
      var iframeVideos = document.getElementsByTagName("iframe");
      for ( var i = 0; i < iframeVideos.length; i++) 
      {
        video = iframeVideos[i];
        alert ( ">" + video.style.width+ "<" );
        video.style.width = "112px";
        video.style.height = "63px";
        alert ( ">" + video.style.width+ "<" );
      }
    }
  </script>
</html>

The page is loaded, and the first alert ( which should have the width of the iframe ) only shows “><“, without the width of the video in between.

I am sure that it’s not because the video object is null. The following lines resize it as expected. After the resizing, the same alert brings up the correct width.

Is there anything I can do to have the width available straight away?

I am not a big fan of libraries such as jQuery, but happy to consider in case one of them gives a straight forward solution which doesn’t make it more complicated than just parsing the string inside the tag. Just in case the page needs some maintenance in the future…

Thanks!

  • 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-05T10:00:35+00:00Added an answer on June 5, 2026 at 10:00 am

    I think that you just need to set the style attribute to match your width and height attributes:

    <iframe style="width:420;height:315" width="420" height="315" src="http://www.youtube.com/embed/a34QTcpnKww"     frameborder="0" allowfullscreen>
        </iframe>
    

    Because in your function, you are working with the style attribute.

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

Sidebar

Related Questions

I have a page which contains several vimeo videos, embedded in the standard iframe
I have a simple Vaadin portlet which displays an Embedded page e.g www.stackoverflow..com. In
I have a very simple page with which a user uploads a file. Using
I have Drag/Drop functionality in my page embedded using YAHOO.js which is initalized at
We have a Wicket app with a page that includes an embedded Youtube video.
I have an HTML page which contains an Object tag to host an embedded
Basically, I have an iframe embedded in a page and the iframe has some
I have a simple page that contains an iframe. The iframe contains a page
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>
I have a simple page with images, and when the user clicks the image,

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.