Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to resize iframe dynamically

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.78k
    Comment on it

    Hello all,

    While working on a project, we came across a situation where we had an iframe that had dynamic content inside it,

    and to make our page responsive, we were not allowed to give fix height to the iframe, but since the iframe had the dynamic content, we wanted to set the size of the iframe on the run time, based on the inner content of it, so to do this we found the

    following solution :

    In JavaScript we use following block of code :

    <script>
      // Set size of iframe dynamically
        function SetSize(id) {
            $('#'+id).height(0);
            var newheight = $('#'+id).contents().height();
            $('#'+id).height(newheight);
            $('#'+id).width('100%');
        }
    <script>
    

    In html we had following block of code :

    <div>
    <iframe id="MyIframe" src="MyPage.html" onload="SetSize('MyIframe')"></iframe>
    </div>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: