2

I need to resize this bootstrap modal based on the height of the iframe content because it is dynamic.

Using an onload and the following function I am getting nothing.

window.resizeIframe = function () {
         var frame = $('#custom-frame');
         var modalHeight = $('#custom-frame').contents().height();
         frame.height(modalHeight);

         $(window).resize(function() {
            frame.height(modalHeight);
         });
      };

I've provided a plunker: http://plnkr.co/edit/eElqXJwvxmpc1XMrdwIK?p=preview

captainrad
  • 3,760
  • 16
  • 41
  • 74

2 Answers2

4

Unless you set it explicitly using a height attribute (which you're not doing), the height of an <iframe> defaults to 150px. Before setting the modal height, you'll need to set the <iframe> height. Some information in this question.

Community
  • 1
  • 1
Stephen Thomas
  • 13,843
  • 2
  • 32
  • 53
2

Using This:

 <div class="media video-container">
                        <iframe width="640" height="390" src="https://www.youtube.com/embed/OqP54KZOz0U" frameborder="0" allowfullscreen></iframe>
                      </div>

And Css is:

.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;}

.video-container iframe,  .video-container object,  .video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;}