Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IFrame Resizer not resizing

I'm working on this page here: http://factor1hosting.com/~dnaz/wordpress/certifications/

And I am trying to pull in a cross domain iframe.

I am using @DavidJBradshaw's iFrame Resizer to achieve this. However, I am not getting the iframe to work correctly.

I can use just the plain javascript init:

<script>iFrameResize({log:true})</script>

And when I use this I do get the log but it does not resize. I've also tried the jQuery method:

$('iframe').iFrameResize( [{log: true}] );

And don't get the log or the iframe resized. I also tried wrapping it in a document ready and that doesn't achieve it either.

Anyone have any thoughts or ideas as to why this isn't firing correctly? My console isn't throwing any JS errors... Thanks!

EDIT: here is an example of how I am currently setup on the HTML side.

<iframe src="http://phpstack-9420-21004-48731.cloudwaysapps.com/onlinecert/certification/login" width="100%" scrolling="no"></iframe>
                <script>
                    jQuery(document).ready(function () {
                        jQuery('iframe').iFrameResize( [{log:true}] );
                    });
                </script>

EDIT 2: Here is my console log when it does fire, and it's setting the iframe to 150px even though the content extends longer then that.

[iFrameSizer][Host page] Added missing iframe ID: iFrameResizer0 (http://phpstack-9420-21004-48731.cloudwaysapps.com/onlinecert/certification/login)
iframeResizer.js:97 
[iFrameSizer][Host page] IFrame scrolling disabled for iFrameResizer0
iframeResizer.js:97 
[iFrameSizer][Host page][init] Sending msg to iframe (iFrameResizer0:8:false:true:32:true:true:null:offset:null:null:0:false:parent)
iframeResizer.js:97 
[iFrameSizer][Host page][iFrame.onload] Sending msg to iframe (iFrameResizer0:8:false:true:32:true:true:null:offset:null:null:0:false:parent)
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] HTML & body height set to "auto"
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Enable public methods
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Added event listener: Animation Start
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Added event listener: Animation Iteration
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Added event listener: Animation End
iframeResizer.contentWindow.js:62 .
[iFrameSizer][iFrameResizer0] Added event listener: Device Orientation Change
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Added event listener: Transition End
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Added event listener: Window Clicked
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Enable MutationObserver
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] In page linking not enabled
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Trigger event lock on
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Sending message to host page (iFrameResizer0:150:703:init)
iframeResizer.js:97 
[iFrameSizer][Host page] Received: 
[iFrameSizer]iFrameResizer0:150:703:init
iframeResizer.js:97 [iFrameSizer][Host page] Checking connection is from: http://phpstack-9420-21004-48731.cloudwaysapps.com
iframeResizer.js:97 
[iFrameSizer][Host page] Checking height is in range 0-Infinity
iframeResizer.js:97 
[iFrameSizer][Host page] Checking width is in range 0-Infinity
iframeResizer.js:97 
[iFrameSizer][Host page] Requesting animation frame
iframeResizer.js:97 
[iFrameSizer][Host page] IFrame (iFrameResizer0) height set to 150px
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] Trigger event lock off
iframeResizer.contentWindow.js:62 
[iFrameSizer][iFrameResizer0] --
like image 702
erwstout Avatar asked Jul 28 '15 23:07

erwstout


People also ask

Can iFrame be resized?

You can easily resize iFrames using HTML and/or CSS, and even make them resizable so they'll adjust automatically based on the user's screen size.

How does iFrame resizer work?

This library enables the automatic resizing of the height and width of both same and cross domain iFrames to fit their contained content. It provides a range of features to address the most common issues with using iFrames, these include: Height and width resizing of the iFrame to content size.


1 Answers

Got it!

The iframe body height wasn't calculating correctly, so I changed how it calculates what the iframe height should be. I am using 'lowestElement' to achieve this and it works great.

iFrameResize({
    log                     : true,                  // Enable console logging
    enablePublicMethods     : true,                  // Enable methods within iframe hosted page
    heightCalculationMethod : 'lowestElement',
});

From the GitHub repo: lowestElement Loops though every element in the the DOM and finds the lowest bottom point

like image 108
erwstout Avatar answered Oct 24 '22 12:10

erwstout